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; |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 26 | import org.onosproject.net.pi.runtime.PiPacketOperation; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 27 | import org.onosproject.net.pi.runtime.PiTableEntry; |
Carmelo Cascone | 87892e2 | 2017-11-13 16:01:29 -0800 | [diff] [blame] | 28 | import org.onosproject.net.pi.model.PiTableId; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 29 | |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 30 | import java.nio.ByteBuffer; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 31 | import java.util.Collection; |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 32 | import java.util.Set; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 33 | import java.util.concurrent.CompletableFuture; |
| 34 | |
| 35 | /** |
| 36 | * Client to control a P4Runtime device. |
| 37 | */ |
| 38 | @Beta |
| 39 | public interface P4RuntimeClient { |
| 40 | |
| 41 | /** |
| 42 | * Type of write operation. |
| 43 | */ |
| 44 | enum WriteOperationType { |
| 45 | UNSPECIFIED, |
| 46 | INSERT, |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 47 | MODIFY, |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 48 | DELETE |
| 49 | } |
| 50 | |
| 51 | /** |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 52 | * Sets the device pipeline according to the given pipeconf, and for the given byte buffer representing the |
| 53 | * target-specific data to be used in the P4Runtime's SetPipelineConfig message. This method should be called |
| 54 | * before any other method of this client. |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 55 | * |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 56 | * @param pipeconf pipeconf |
| 57 | * @param deviceData target-specific data |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 58 | * @return a completable future of a boolean, true if the operations was successful, false otherwise. |
| 59 | */ |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 60 | CompletableFuture<Boolean> setPipelineConfig(PiPipeconf pipeconf, ByteBuffer deviceData); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * Initializes the stream channel, after which all messages received from the device will be notified using the |
| 64 | * {@link P4RuntimeController} event listener. |
| 65 | * |
| 66 | * @return a completable future of a boolean, true if the operations was successful, false otherwise. |
| 67 | */ |
| 68 | CompletableFuture<Boolean> initStreamChannel(); |
| 69 | |
| 70 | /** |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 71 | * Performs the given write operation for the given table entries and pipeconf. |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 72 | * |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 73 | * @param entries table entries |
| 74 | * @param opType operation type |
| 75 | * @param pipeconf pipeconf currently deployed on the device |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 76 | * @return true if the operation was successful, false otherwise. |
| 77 | */ |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 78 | CompletableFuture<Boolean> writeTableEntries(Collection<PiTableEntry> entries, WriteOperationType opType, |
| 79 | PiPipeconf pipeconf); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 80 | |
| 81 | /** |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 82 | * 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] | 83 | * |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 84 | * @param tableId table identifier |
| 85 | * @param pipeconf pipeconf currently deployed on the device |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 86 | * @return completable future of a collection of table entries |
| 87 | */ |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 88 | CompletableFuture<Collection<PiTableEntry>> dumpTable(PiTableId tableId, PiPipeconf pipeconf); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 89 | |
| 90 | /** |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 91 | * Executes a packet-out operation for the given pipeconf. |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 92 | * |
| 93 | * @param packet packet-out operation to be performed by the device |
| 94 | * @param pipeconf pipeconf currently deployed on the device |
| 95 | * @return a completable future of a boolean, true if the operations was successful, false otherwise. |
| 96 | */ |
| 97 | CompletableFuture<Boolean> packetOut(PiPacketOperation packet, PiPipeconf pipeconf); |
| 98 | |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 99 | /** |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 100 | * Returns the value of all counter cells for the given set of counter identifiers and pipeconf. |
| 101 | * |
| 102 | * @param counterIds counter identifiers |
| 103 | * @param pipeconf pipeconf |
| 104 | * @return collection of counter data |
| 105 | */ |
| 106 | CompletableFuture<Collection<PiCounterCellData>> readAllCounterCells(Set<PiCounterId> counterIds, |
| 107 | PiPipeconf pipeconf); |
| 108 | |
| 109 | /** |
| 110 | * Returns a collection of counter data corresponding to the given set of counter cell identifiers, for the given |
| 111 | * pipeconf. |
| 112 | * |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 113 | * @param cellIds set of counter cell identifiers |
| 114 | * @param pipeconf pipeconf |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 115 | * @return collection of counter data |
| 116 | */ |
| 117 | CompletableFuture<Collection<PiCounterCellData>> readCounterCells(Set<PiCounterCellId> cellIds, |
| 118 | PiPipeconf pipeconf); |
| 119 | |
| 120 | /** |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 121 | * Performs the given write operation for the given action group members and pipeconf. |
| 122 | * |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 123 | * @param group action group |
| 124 | * @param opType write operation type |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 125 | * @param pipeconf the pipeconf currently deployed on the device |
| 126 | * @return true if the operation was successful, false otherwise |
| 127 | */ |
| 128 | CompletableFuture<Boolean> writeActionGroupMembers(PiActionGroup group, |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 129 | WriteOperationType opType, |
| 130 | PiPipeconf pipeconf); |
| 131 | |
| 132 | /** |
| 133 | * Performs the given write operation for the given action group and pipeconf. |
| 134 | * |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 135 | * @param group the action group |
| 136 | * @param opType write operation type |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 137 | * @param pipeconf the pipeconf currently deployed on the device |
| 138 | * @return true if the operation was successful, false otherwise |
| 139 | */ |
| 140 | CompletableFuture<Boolean> writeActionGroup(PiActionGroup group, |
| 141 | WriteOperationType opType, |
| 142 | PiPipeconf pipeconf); |
| 143 | |
| 144 | /** |
| 145 | * Dumps all groups currently installed for the given action profile. |
| 146 | * |
| 147 | * @param actionProfileId the action profile id |
Carmelo Cascone | d61fdb3 | 2017-10-30 10:09:57 -0700 | [diff] [blame] | 148 | * @param pipeconf the pipeconf currently deployed on the device |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame] | 149 | * @return completable future of a collection of groups |
| 150 | */ |
| 151 | CompletableFuture<Collection<PiActionGroup>> dumpGroups(PiActionProfileId actionProfileId, |
| 152 | PiPipeconf pipeconf); |
| 153 | |
| 154 | /** |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 155 | * Shutdown the client by terminating any active RPC such as the stream channel. |
| 156 | */ |
| 157 | void shutdown(); |
| 158 | |
Yi Tseng | 3e7f145 | 2017-10-20 10:31:53 -0700 | [diff] [blame] | 159 | /** |
| 160 | * Sends a master arbitration update to the device. |
| 161 | * |
| 162 | * @return a completable future containing true if the operation was successful; false otherwise |
| 163 | */ |
| 164 | CompletableFuture<Boolean> sendMasterArbitrationUpdate(); |
| 165 | |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 166 | // TODO: work in progress. |
| 167 | } |