blob: a9a6e086b06f4b48219a854bddcd9166e3476973 [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;
Andrea Campanella432f7182017-07-14 18:43:27 +020031import org.onosproject.net.pi.runtime.PiPacketOperation;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040032import org.onosproject.net.pi.runtime.PiTableEntry;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040033
Carmelo Casconed61fdb32017-10-30 10:09:57 -070034import java.nio.ByteBuffer;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040035import java.util.Collection;
Carmelo Casconeb045ddc2017-09-01 01:26:35 +020036import java.util.Set;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040037import java.util.concurrent.CompletableFuture;
38
39/**
40 * Client to control a P4Runtime device.
41 */
42@Beta
43public interface P4RuntimeClient {
44
45 /**
46 * Type of write operation.
47 */
48 enum WriteOperationType {
49 UNSPECIFIED,
50 INSERT,
Carmelo Cascone8d99b172017-07-18 17:26:31 -040051 MODIFY,
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040052 DELETE
53 }
54
55 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +020056 * Starts the client by starting the Stream RPC with the device.
57 *
58 * @return completable future containing true if the operation was
59 * successful, false otherwise.
60 */
61 CompletableFuture<Boolean> start();
62
63 /**
64 * Shutdowns the client by terminating any active RPC such as the Stream
65 * one.
66 *
67 * @return a completable future to signal the completion of the shutdown
68 * procedure
69 */
70 CompletableFuture<Void> shutdown();
71
72 /**
73 * Sends a master arbitration update to the device with a new election ID
74 * that is guaranteed to be the highest value between all clients.
75 *
76 * @return completable future containing true if the operation was
77 * successful; false otherwise
78 */
79 CompletableFuture<Boolean> becomeMaster();
80
81 /**
82 * Sets the device pipeline according to the given pipeconf, and for the
83 * given byte buffer representing the target-specific data to be used in the
84 * P4Runtime's SetPipelineConfig message. This method should be called
Carmelo Casconed61fdb32017-10-30 10:09:57 -070085 * before any other method of this client.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040086 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -070087 * @param pipeconf pipeconf
88 * @param deviceData target-specific data
Carmelo Casconee5b28722018-06-22 17:28:28 +020089 * @return a completable future of a boolean, true if the operations was
90 * successful, false otherwise.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040091 */
Carmelo Casconee5b28722018-06-22 17:28:28 +020092 CompletableFuture<Boolean> setPipelineConfig(
93 PiPipeconf pipeconf, ByteBuffer deviceData);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040094
95 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +020096 * Performs the given write operation for the given table entries and
97 * pipeconf.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040098 *
Carmelo Cascone8d99b172017-07-18 17:26:31 -040099 * @param entries table entries
100 * @param opType operation type
101 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400102 * @return true if the operation was successful, false otherwise.
103 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200104 CompletableFuture<Boolean> writeTableEntries(
105 Collection<PiTableEntry> entries, WriteOperationType opType,
106 PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400107
108 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200109 * Dumps all entries currently installed in the given table, for the given
110 * pipeconf.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400111 *
Carmelo Cascone8d99b172017-07-18 17:26:31 -0400112 * @param tableId table identifier
113 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400114 * @return completable future of a collection of table entries
115 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200116 CompletableFuture<Collection<PiTableEntry>> dumpTable(
117 PiTableId tableId, PiPipeconf pipeconf);
118
119 /**
120 * Dumps entries from all tables, for the given pipeconf.
121 *
122 * @param pipeconf pipeconf currently deployed on the device
123 * @return completable future of a collection of table entries
124 */
125 CompletableFuture<Collection<PiTableEntry>> dumpAllTables(PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400126
127 /**
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200128 * Executes a packet-out operation for the given pipeconf.
Andrea Campanella432f7182017-07-14 18:43:27 +0200129 *
130 * @param packet packet-out operation to be performed by the device
131 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconee5b28722018-06-22 17:28:28 +0200132 * @return a completable future of a boolean, true if the operations was
133 * successful, false otherwise.
Andrea Campanella432f7182017-07-14 18:43:27 +0200134 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200135 CompletableFuture<Boolean> packetOut(
136 PiPacketOperation packet, PiPipeconf pipeconf);
Andrea Campanella432f7182017-07-14 18:43:27 +0200137
Andrea Campanella432f7182017-07-14 18:43:27 +0200138 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200139 * Returns the value of all counter cells for the given set of counter
140 * identifiers and pipeconf.
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200141 *
142 * @param counterIds counter identifiers
143 * @param pipeconf pipeconf
144 * @return collection of counter data
145 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200146 CompletableFuture<Collection<PiCounterCellData>> readAllCounterCells(
147 Set<PiCounterId> counterIds, PiPipeconf pipeconf);
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200148
149 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200150 * Returns a collection of counter data corresponding to the given set of
151 * counter cell identifiers, for the given pipeconf.
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200152 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700153 * @param cellIds set of counter cell identifiers
154 * @param pipeconf pipeconf
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200155 * @return collection of counter data
156 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200157 CompletableFuture<Collection<PiCounterCellData>> readCounterCells(
158 Set<PiCounterCellId> cellIds, PiPipeconf pipeconf);
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200159
160 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200161 * Performs the given write operation for the given action group members and
162 * pipeconf.
Yi Tseng82512da2017-08-16 19:46:36 -0700163 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200164 * @param profileId action group profile ID
165 * @param members action group members
166 * @param opType write operation type
167 * @param pipeconf the pipeconf currently deployed on the device
Yi Tseng82512da2017-08-16 19:46:36 -0700168 * @return true if the operation was successful, false otherwise
169 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200170 CompletableFuture<Boolean> writeActionGroupMembers(
171 PiActionProfileId profileId, Collection<PiActionGroupMember> members,
172 WriteOperationType opType, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700173
174 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200175 * Performs the given write operation for the given action group and
176 * pipeconf.
Yi Tseng82512da2017-08-16 19:46:36 -0700177 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700178 * @param group the action group
179 * @param opType write operation type
Yi Tseng82512da2017-08-16 19:46:36 -0700180 * @param pipeconf the pipeconf currently deployed on the device
181 * @return true if the operation was successful, false otherwise
182 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200183 CompletableFuture<Boolean> writeActionGroup(
184 PiActionGroup group, WriteOperationType opType, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700185
186 /**
187 * Dumps all groups currently installed for the given action profile.
188 *
189 * @param actionProfileId the action profile id
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700190 * @param pipeconf the pipeconf currently deployed on the device
Yi Tseng82512da2017-08-16 19:46:36 -0700191 * @return completable future of a collection of groups
192 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200193 CompletableFuture<Collection<PiActionGroup>> dumpGroups(
194 PiActionProfileId actionProfileId, PiPipeconf pipeconf);
Yi Tseng82512da2017-08-16 19:46:36 -0700195
196 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200197 * Returns the configuration of all meter cells for the given set of meter
198 * identifiers and pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900199 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200200 * @param meterIds meter identifiers
201 * @param pipeconf pipeconf
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900202 * @return collection of meter configurations
203 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200204 CompletableFuture<Collection<PiMeterCellConfig>> readAllMeterCells(
205 Set<PiMeterId> meterIds, PiPipeconf pipeconf);
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900206
207 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200208 * Returns a collection of meter configurations corresponding to the given
209 * set of meter cell identifiers, for the given pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900210 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200211 * @param cellIds set of meter cell identifiers
212 * @param pipeconf pipeconf
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900213 * @return collection of meter configrations
214 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200215 CompletableFuture<Collection<PiMeterCellConfig>> readMeterCells(
216 Set<PiMeterCellId> cellIds, PiPipeconf pipeconf);
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900217
218 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +0200219 * Performs a write operation for the given meter configurations and
220 * pipeconf.
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900221 *
Carmelo Casconee5b28722018-06-22 17:28:28 +0200222 * @param cellConfigs meter cell configurations
223 * @param pipeconf pipeconf currently deployed on the device
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900224 * @return true if the operation was successful, false otherwise.
225 */
Carmelo Casconee5b28722018-06-22 17:28:28 +0200226 CompletableFuture<Boolean> writeMeterCells(
227 Collection<PiMeterCellConfig> cellConfigs, PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400228}