Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | package org.onosproject.p4runtime.api; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 20 | import org.onosproject.net.pi.model.PiActionProfileId; |
Carmelo Cascone | 81929aa | 2018-04-07 01:38:55 -0700 | [diff] [blame] | 21 | import org.onosproject.net.pi.model.PiCounterId; |
| 22 | import org.onosproject.net.pi.model.PiMeterId; |
| 23 | import org.onosproject.net.pi.model.PiPipeconf; |
| 24 | import org.onosproject.net.pi.model.PiTableId; |
| 25 | import org.onosproject.net.pi.runtime.PiActionGroup; |
Yi Tseng | 8d35513 | 2018-04-13 01:40:48 +0800 | [diff] [blame] | 26 | import org.onosproject.net.pi.runtime.PiActionGroupMember; |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 27 | import org.onosproject.net.pi.runtime.PiCounterCellData; |
| 28 | import org.onosproject.net.pi.runtime.PiCounterCellId; |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 29 | import org.onosproject.net.pi.runtime.PiMeterCellConfig; |
| 30 | import org.onosproject.net.pi.runtime.PiMeterCellId; |
Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 31 | import org.onosproject.net.pi.runtime.PiMulticastGroupEntry; |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 32 | import org.onosproject.net.pi.runtime.PiPacketOperation; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 33 | import org.onosproject.net.pi.runtime.PiTableEntry; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 34 | |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 35 | import java.nio.ByteBuffer; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 36 | import java.util.Collection; |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 37 | import java.util.Set; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 38 | import java.util.concurrent.CompletableFuture; |
| 39 | |
| 40 | /** |
| 41 | * Client to control a P4Runtime device. |
| 42 | */ |
| 43 | @Beta |
| 44 | public interface P4RuntimeClient { |
| 45 | |
| 46 | /** |
| 47 | * Type of write operation. |
| 48 | */ |
| 49 | enum WriteOperationType { |
| 50 | UNSPECIFIED, |
| 51 | INSERT, |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 52 | MODIFY, |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 53 | DELETE |
| 54 | } |
| 55 | |
| 56 | /** |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 57 | * 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 Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 86 | * before any other method of this client. |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 87 | * |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 88 | * @param pipeconf pipeconf |
| 89 | * @param deviceData target-specific data |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 90 | * @return a completable future of a boolean, true if the operations was |
| 91 | * successful, false otherwise. |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 92 | */ |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 93 | CompletableFuture<Boolean> setPipelineConfig( |
| 94 | PiPipeconf pipeconf, ByteBuffer deviceData); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 95 | |
| 96 | /** |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 97 | * Performs the given write operation for the given table entries and |
| 98 | * pipeconf. |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 99 | * |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 100 | * @param entries table entries |
| 101 | * @param opType operation type |
| 102 | * @param pipeconf pipeconf currently deployed on the device |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 103 | * @return true if the operation was successful, false otherwise. |
| 104 | */ |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 105 | CompletableFuture<Boolean> writeTableEntries( |
| 106 | Collection<PiTableEntry> entries, WriteOperationType opType, |
| 107 | PiPipeconf pipeconf); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 108 | |
| 109 | /** |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 110 | * Dumps all entries currently installed in the given table, for the given |
| 111 | * pipeconf. |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 112 | * |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 113 | * @param tableId table identifier |
| 114 | * @param pipeconf pipeconf currently deployed on the device |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 115 | * @return completable future of a collection of table entries |
| 116 | */ |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 117 | 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 Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 127 | |
| 128 | /** |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 129 | * Executes a packet-out operation for the given pipeconf. |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 130 | * |
| 131 | * @param packet packet-out operation to be performed by the device |
| 132 | * @param pipeconf pipeconf currently deployed on the device |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 133 | * @return a completable future of a boolean, true if the operations was |
| 134 | * successful, false otherwise. |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 135 | */ |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 136 | CompletableFuture<Boolean> packetOut( |
| 137 | PiPacketOperation packet, PiPipeconf pipeconf); |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 138 | |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 139 | /** |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 140 | * Returns the value of all counter cells for the given set of counter |
| 141 | * identifiers and pipeconf. |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 142 | * |
| 143 | * @param counterIds counter identifiers |
| 144 | * @param pipeconf pipeconf |
| 145 | * @return collection of counter data |
| 146 | */ |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 147 | CompletableFuture<Collection<PiCounterCellData>> readAllCounterCells( |
| 148 | Set<PiCounterId> counterIds, PiPipeconf pipeconf); |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 149 | |
| 150 | /** |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 151 | * Returns a collection of counter data corresponding to the given set of |
| 152 | * counter cell identifiers, for the given pipeconf. |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 153 | * |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 154 | * @param cellIds set of counter cell identifiers |
| 155 | * @param pipeconf pipeconf |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 156 | * @return collection of counter data |
| 157 | */ |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 158 | CompletableFuture<Collection<PiCounterCellData>> readCounterCells( |
| 159 | Set<PiCounterCellId> cellIds, PiPipeconf pipeconf); |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 160 | |
| 161 | /** |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 162 | * Performs the given write operation for the given action group members and |
| 163 | * pipeconf. |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 164 | * |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 165 | * @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 Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 169 | * @return true if the operation was successful, false otherwise |
| 170 | */ |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 171 | CompletableFuture<Boolean> writeActionGroupMembers( |
| 172 | PiActionProfileId profileId, Collection<PiActionGroupMember> members, |
| 173 | WriteOperationType opType, PiPipeconf pipeconf); |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 174 | |
| 175 | /** |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 176 | * Performs the given write operation for the given action group and |
| 177 | * pipeconf. |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 178 | * |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 179 | * @param group the action group |
| 180 | * @param opType write operation type |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 181 | * @param pipeconf the pipeconf currently deployed on the device |
| 182 | * @return true if the operation was successful, false otherwise |
| 183 | */ |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 184 | CompletableFuture<Boolean> writeActionGroup( |
| 185 | PiActionGroup group, WriteOperationType opType, PiPipeconf pipeconf); |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 186 | |
| 187 | /** |
| 188 | * Dumps all groups currently installed for the given action profile. |
| 189 | * |
| 190 | * @param actionProfileId the action profile id |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 191 | * @param pipeconf the pipeconf currently deployed on the device |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 192 | * @return completable future of a collection of groups |
| 193 | */ |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 194 | CompletableFuture<Collection<PiActionGroup>> dumpGroups( |
| 195 | PiActionProfileId actionProfileId, PiPipeconf pipeconf); |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 196 | |
| 197 | /** |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 198 | * Returns the configuration of all meter cells for the given set of meter |
| 199 | * identifiers and pipeconf. |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 200 | * |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 201 | * @param meterIds meter identifiers |
| 202 | * @param pipeconf pipeconf |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 203 | * @return collection of meter configurations |
| 204 | */ |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 205 | CompletableFuture<Collection<PiMeterCellConfig>> readAllMeterCells( |
| 206 | Set<PiMeterId> meterIds, PiPipeconf pipeconf); |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 207 | |
| 208 | /** |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 209 | * Returns a collection of meter configurations corresponding to the given |
| 210 | * set of meter cell identifiers, for the given pipeconf. |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 211 | * |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 212 | * @param cellIds set of meter cell identifiers |
| 213 | * @param pipeconf pipeconf |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 214 | * @return collection of meter configrations |
| 215 | */ |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 216 | CompletableFuture<Collection<PiMeterCellConfig>> readMeterCells( |
| 217 | Set<PiMeterCellId> cellIds, PiPipeconf pipeconf); |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 218 | |
| 219 | /** |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 220 | * Performs a write operation for the given meter configurations and |
| 221 | * pipeconf. |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 222 | * |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 223 | * @param cellConfigs meter cell configurations |
| 224 | * @param pipeconf pipeconf currently deployed on the device |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame] | 225 | * @return true if the operation was successful, false otherwise. |
| 226 | */ |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 227 | CompletableFuture<Boolean> writeMeterCells( |
| 228 | Collection<PiMeterCellConfig> cellConfigs, PiPipeconf pipeconf); |
Carmelo Cascone | 5813681 | 2018-07-19 03:40:16 +0200 | [diff] [blame] | 229 | |
| 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 Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 248 | } |