blob: 91254cfb779b855699fa20a4ed345869ccdc18cd [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;
Andrea Campanella432f7182017-07-14 18:43:27 +020020import org.onosproject.net.pi.model.PiPipeconf;
Carmelo Cascone87b9b392017-10-02 18:33:20 +020021import org.onosproject.net.pi.runtime.PiActionGroup;
Carmelo Cascone87892e22017-11-13 16:01:29 -080022import org.onosproject.net.pi.model.PiActionProfileId;
Carmelo Casconeb045ddc2017-09-01 01:26:35 +020023import org.onosproject.net.pi.runtime.PiCounterCellData;
24import org.onosproject.net.pi.runtime.PiCounterCellId;
Carmelo Cascone87892e22017-11-13 16:01:29 -080025import org.onosproject.net.pi.model.PiCounterId;
Frank Wangd7e3b4b2017-09-24 13:37:54 +090026import org.onosproject.net.pi.runtime.PiMeterCellConfig;
27import org.onosproject.net.pi.runtime.PiMeterCellId;
28import org.onosproject.net.pi.model.PiMeterId;
Andrea Campanella432f7182017-07-14 18:43:27 +020029import org.onosproject.net.pi.runtime.PiPacketOperation;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040030import org.onosproject.net.pi.runtime.PiTableEntry;
Carmelo Cascone87892e22017-11-13 16:01:29 -080031import org.onosproject.net.pi.model.PiTableId;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040032
Carmelo Casconed61fdb32017-10-30 10:09:57 -070033import java.nio.ByteBuffer;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040034import java.util.Collection;
Carmelo Casconeb045ddc2017-09-01 01:26:35 +020035import java.util.Set;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040036import java.util.concurrent.CompletableFuture;
37
38/**
39 * Client to control a P4Runtime device.
40 */
41@Beta
42public interface P4RuntimeClient {
43
44 /**
45 * Type of write operation.
46 */
47 enum WriteOperationType {
48 UNSPECIFIED,
49 INSERT,
Carmelo Cascone8d99b172017-07-18 17:26:31 -040050 MODIFY,
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040051 DELETE
52 }
53
54 /**
Carmelo Casconed61fdb32017-10-30 10:09:57 -070055 * Sets the device pipeline according to the given pipeconf, and for the given byte buffer representing the
56 * target-specific data to be used in the P4Runtime's SetPipelineConfig message. This method should be called
57 * before any other method of this client.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040058 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -070059 * @param pipeconf pipeconf
60 * @param deviceData target-specific data
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040061 * @return a completable future of a boolean, true if the operations was successful, false otherwise.
62 */
Carmelo Casconed61fdb32017-10-30 10:09:57 -070063 CompletableFuture<Boolean> setPipelineConfig(PiPipeconf pipeconf, ByteBuffer deviceData);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040064
65 /**
66 * Initializes the stream channel, after which all messages received from the device will be notified using the
67 * {@link P4RuntimeController} event listener.
68 *
69 * @return a completable future of a boolean, true if the operations was successful, false otherwise.
70 */
71 CompletableFuture<Boolean> initStreamChannel();
72
73 /**
Carmelo Cascone8d99b172017-07-18 17:26:31 -040074 * Performs the given write operation for the given table entries and pipeconf.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040075 *
Carmelo Cascone8d99b172017-07-18 17:26:31 -040076 * @param entries table entries
77 * @param opType operation type
78 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040079 * @return true if the operation was successful, false otherwise.
80 */
Carmelo Cascone8d99b172017-07-18 17:26:31 -040081 CompletableFuture<Boolean> writeTableEntries(Collection<PiTableEntry> entries, WriteOperationType opType,
82 PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040083
84 /**
Carmelo Casconeb045ddc2017-09-01 01:26:35 +020085 * Dumps all entries currently installed in the given table, for the given pipeconf.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040086 *
Carmelo Cascone8d99b172017-07-18 17:26:31 -040087 * @param tableId table identifier
88 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040089 * @return completable future of a collection of table entries
90 */
Carmelo Cascone8d99b172017-07-18 17:26:31 -040091 CompletableFuture<Collection<PiTableEntry>> dumpTable(PiTableId tableId, PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040092
93 /**
Carmelo Casconeb045ddc2017-09-01 01:26:35 +020094 * Executes a packet-out operation for the given pipeconf.
Andrea Campanella432f7182017-07-14 18:43:27 +020095 *
96 * @param packet packet-out operation to be performed by the device
97 * @param pipeconf pipeconf currently deployed on the device
98 * @return a completable future of a boolean, true if the operations was successful, false otherwise.
99 */
100 CompletableFuture<Boolean> packetOut(PiPacketOperation packet, PiPipeconf pipeconf);
101
Andrea Campanella432f7182017-07-14 18:43:27 +0200102 /**
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200103 * Returns the value of all counter cells for the given set of counter identifiers and pipeconf.
104 *
105 * @param counterIds counter identifiers
106 * @param pipeconf pipeconf
107 * @return collection of counter data
108 */
109 CompletableFuture<Collection<PiCounterCellData>> readAllCounterCells(Set<PiCounterId> counterIds,
110 PiPipeconf pipeconf);
111
112 /**
113 * Returns a collection of counter data corresponding to the given set of counter cell identifiers, for the given
114 * pipeconf.
115 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700116 * @param cellIds set of counter cell identifiers
117 * @param pipeconf pipeconf
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200118 * @return collection of counter data
119 */
120 CompletableFuture<Collection<PiCounterCellData>> readCounterCells(Set<PiCounterCellId> cellIds,
121 PiPipeconf pipeconf);
122
123 /**
Yi Tseng82512da2017-08-16 19:46:36 -0700124 * Performs the given write operation for the given action group members and pipeconf.
125 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700126 * @param group action group
127 * @param opType write operation type
Yi Tseng82512da2017-08-16 19:46:36 -0700128 * @param pipeconf the pipeconf currently deployed on the device
129 * @return true if the operation was successful, false otherwise
130 */
131 CompletableFuture<Boolean> writeActionGroupMembers(PiActionGroup group,
Yi Tseng82512da2017-08-16 19:46:36 -0700132 WriteOperationType opType,
133 PiPipeconf pipeconf);
134
135 /**
136 * Performs the given write operation for the given action group and pipeconf.
137 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700138 * @param group the action group
139 * @param opType write operation type
Yi Tseng82512da2017-08-16 19:46:36 -0700140 * @param pipeconf the pipeconf currently deployed on the device
141 * @return true if the operation was successful, false otherwise
142 */
143 CompletableFuture<Boolean> writeActionGroup(PiActionGroup group,
144 WriteOperationType opType,
145 PiPipeconf pipeconf);
146
147 /**
148 * Dumps all groups currently installed for the given action profile.
149 *
150 * @param actionProfileId the action profile id
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700151 * @param pipeconf the pipeconf currently deployed on the device
Yi Tseng82512da2017-08-16 19:46:36 -0700152 * @return completable future of a collection of groups
153 */
154 CompletableFuture<Collection<PiActionGroup>> dumpGroups(PiActionProfileId actionProfileId,
155 PiPipeconf pipeconf);
156
157 /**
Frank Wangd7e3b4b2017-09-24 13:37:54 +0900158 * Returns the configuration of all meter cells for the given set of meter identifiers and pipeconf.
159 *
160 * @param meterIds meter identifiers
161 * @param pipeconf pipeconf
162 * @return collection of meter configurations
163 */
164 CompletableFuture<Collection<PiMeterCellConfig>> readAllMeterCells(Set<PiMeterId> meterIds,
165 PiPipeconf pipeconf);
166
167 /**
168 * Returns a collection of meter configurations corresponding to the given set of meter cell identifiers,
169 * for the given pipeconf.
170 *
171 * @param cellIds set of meter cell identifiers
172 * @param pipeconf pipeconf
173 * @return collection of meter configrations
174 */
175 CompletableFuture<Collection<PiMeterCellConfig>> readMeterCells(Set<PiMeterCellId> cellIds,
176 PiPipeconf pipeconf);
177
178 /**
179 * Performs a write operation for the given meter configurations and pipeconf.
180 *
181 * @param cellConfigs meter cell configurations
182 * @param pipeconf pipeconf currently deployed on the device
183 * @return true if the operation was successful, false otherwise.
184 */
185 CompletableFuture<Boolean> writeMeterCells(Collection<PiMeterCellConfig> cellConfigs, PiPipeconf pipeconf);
186
187 /**
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400188 * Shutdown the client by terminating any active RPC such as the stream channel.
189 */
190 void shutdown();
191
Yi Tseng3e7f1452017-10-20 10:31:53 -0700192 /**
193 * Sends a master arbitration update to the device.
194 *
195 * @return a completable future containing true if the operation was successful; false otherwise
196 */
197 CompletableFuture<Boolean> sendMasterArbitrationUpdate();
198
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400199 // TODO: work in progress.
200}