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