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; |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 20 | import org.onosproject.net.pi.model.PiPipeconf; |
Carmelo Cascone | 87b9b39 | 2017-10-02 18:33:20 +0200 | [diff] [blame] | 21 | import org.onosproject.net.pi.runtime.PiActionGroup; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 22 | import org.onosproject.net.pi.model.PiActionProfileId; |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 23 | import org.onosproject.net.pi.runtime.PiCounterCellData; |
| 24 | import org.onosproject.net.pi.runtime.PiCounterCellId; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 25 | import org.onosproject.net.pi.model.PiCounterId; |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame^] | 26 | import org.onosproject.net.pi.runtime.PiMeterCellConfig; |
| 27 | import org.onosproject.net.pi.runtime.PiMeterCellId; |
| 28 | import org.onosproject.net.pi.model.PiMeterId; |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 29 | import org.onosproject.net.pi.runtime.PiPacketOperation; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 30 | import org.onosproject.net.pi.runtime.PiTableEntry; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 31 | import org.onosproject.net.pi.model.PiTableId; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 32 | |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 33 | import java.nio.ByteBuffer; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 34 | import java.util.Collection; |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 35 | import java.util.Set; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 36 | import java.util.concurrent.CompletableFuture; |
| 37 | |
| 38 | /** |
| 39 | * Client to control a P4Runtime device. |
| 40 | */ |
| 41 | @Beta |
| 42 | public interface P4RuntimeClient { |
| 43 | |
| 44 | /** |
| 45 | * Type of write operation. |
| 46 | */ |
| 47 | enum WriteOperationType { |
| 48 | UNSPECIFIED, |
| 49 | INSERT, |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 50 | MODIFY, |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 51 | DELETE |
| 52 | } |
| 53 | |
| 54 | /** |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 55 | * 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 Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 58 | * |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 59 | * @param pipeconf pipeconf |
| 60 | * @param deviceData target-specific data |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 61 | * @return a completable future of a boolean, true if the operations was successful, false otherwise. |
| 62 | */ |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 63 | CompletableFuture<Boolean> setPipelineConfig(PiPipeconf pipeconf, ByteBuffer deviceData); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 64 | |
| 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 Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 74 | * Performs the given write operation for the given table entries and pipeconf. |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 75 | * |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 76 | * @param entries table entries |
| 77 | * @param opType operation type |
| 78 | * @param pipeconf pipeconf currently deployed on the device |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 79 | * @return true if the operation was successful, false otherwise. |
| 80 | */ |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 81 | CompletableFuture<Boolean> writeTableEntries(Collection<PiTableEntry> entries, WriteOperationType opType, |
| 82 | PiPipeconf pipeconf); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 83 | |
| 84 | /** |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 85 | * Dumps all entries currently installed in the given table, for the given pipeconf. |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 86 | * |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 87 | * @param tableId table identifier |
| 88 | * @param pipeconf pipeconf currently deployed on the device |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 89 | * @return completable future of a collection of table entries |
| 90 | */ |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 91 | CompletableFuture<Collection<PiTableEntry>> dumpTable(PiTableId tableId, PiPipeconf pipeconf); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 92 | |
| 93 | /** |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 94 | * Executes a packet-out operation for the given pipeconf. |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 95 | * |
| 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 Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 102 | /** |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 103 | * 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 Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 116 | * @param cellIds set of counter cell identifiers |
| 117 | * @param pipeconf pipeconf |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 118 | * @return collection of counter data |
| 119 | */ |
| 120 | CompletableFuture<Collection<PiCounterCellData>> readCounterCells(Set<PiCounterCellId> cellIds, |
| 121 | PiPipeconf pipeconf); |
| 122 | |
| 123 | /** |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 124 | * Performs the given write operation for the given action group members and pipeconf. |
| 125 | * |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 126 | * @param group action group |
| 127 | * @param opType write operation type |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 128 | * @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 Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 132 | WriteOperationType opType, |
| 133 | PiPipeconf pipeconf); |
| 134 | |
| 135 | /** |
| 136 | * Performs the given write operation for the given action group and pipeconf. |
| 137 | * |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 138 | * @param group the action group |
| 139 | * @param opType write operation type |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 140 | * @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 Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 151 | * @param pipeconf the pipeconf currently deployed on the device |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 152 | * @return completable future of a collection of groups |
| 153 | */ |
| 154 | CompletableFuture<Collection<PiActionGroup>> dumpGroups(PiActionProfileId actionProfileId, |
| 155 | PiPipeconf pipeconf); |
| 156 | |
| 157 | /** |
Frank Wang | d7e3b4b | 2017-09-24 13:37:54 +0900 | [diff] [blame^] | 158 | * 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 Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 188 | * Shutdown the client by terminating any active RPC such as the stream channel. |
| 189 | */ |
| 190 | void shutdown(); |
| 191 | |
Yi Tseng | 3e7f145 | 2017-10-20 10:31:53 -0700 | [diff] [blame] | 192 | /** |
| 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 Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 199 | // TODO: work in progress. |
| 200 | } |