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; |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame^] | 21 | import org.onosproject.net.pi.runtime.PiActionProfileId; |
Carmelo Cascone | b045ddc | 2017-09-01 01:26:35 +0200 | [diff] [blame] | 22 | import org.onosproject.net.pi.runtime.PiCounterCellData; |
| 23 | import org.onosproject.net.pi.runtime.PiCounterCellId; |
| 24 | import org.onosproject.net.pi.runtime.PiCounterId; |
Yi Tseng | 82512da | 2017-08-16 19:46:36 -0700 | [diff] [blame^] | 25 | import org.onosproject.net.pi.runtime.PiActionGroup; |
| 26 | import org.onosproject.net.pi.runtime.PiActionGroupMember; |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 27 | import org.onosproject.net.pi.runtime.PiPacketOperation; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 28 | import org.onosproject.net.pi.runtime.PiTableEntry; |
| 29 | import org.onosproject.net.pi.runtime.PiTableId; |
| 30 | |
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 | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 52 | * Sets the pipeline configuration defined by the given pipeconf for the given target-specific configuration |
| 53 | * extension type (e.g. {@link PiPipeconf.ExtensionType#BMV2_JSON}, or {@link PiPipeconf.ExtensionType#TOFINO_BIN}). |
| 54 | * This method should be called before any other method of this client. |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 55 | * |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 56 | * @param pipeconf pipeconf |
| 57 | * @param targetConfigExtType extension type of the target-specific configuration |
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 | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame] | 60 | CompletableFuture<Boolean> setPipelineConfig(PiPipeconf pipeconf, PiPipeconf.ExtensionType targetConfigExtType); |
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 | * |
| 113 | * @param cellIds set of counter cell identifiers |
| 114 | * @param pipeconf pipeconf |
| 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 | * |
| 123 | * @param group action group |
| 124 | * @param members the collection of action group members |
| 125 | * @param opType write operation type |
| 126 | * @param pipeconf the pipeconf currently deployed on the device |
| 127 | * @return true if the operation was successful, false otherwise |
| 128 | */ |
| 129 | CompletableFuture<Boolean> writeActionGroupMembers(PiActionGroup group, |
| 130 | Collection<PiActionGroupMember> members, |
| 131 | WriteOperationType opType, |
| 132 | PiPipeconf pipeconf); |
| 133 | |
| 134 | /** |
| 135 | * Performs the given write operation for the given action group and pipeconf. |
| 136 | * |
| 137 | * @param group the action group |
| 138 | * @param opType write operation type |
| 139 | * @param pipeconf the pipeconf currently deployed on the device |
| 140 | * @return true if the operation was successful, false otherwise |
| 141 | */ |
| 142 | CompletableFuture<Boolean> writeActionGroup(PiActionGroup group, |
| 143 | WriteOperationType opType, |
| 144 | PiPipeconf pipeconf); |
| 145 | |
| 146 | /** |
| 147 | * Dumps all groups currently installed for the given action profile. |
| 148 | * |
| 149 | * @param actionProfileId the action profile id |
| 150 | * @param pipeconf the pipeconf currently deployed on the device |
| 151 | * @return completable future of a collection of groups |
| 152 | */ |
| 153 | CompletableFuture<Collection<PiActionGroup>> dumpGroups(PiActionProfileId actionProfileId, |
| 154 | PiPipeconf pipeconf); |
| 155 | |
| 156 | /** |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 157 | * Shutdown the client by terminating any active RPC such as the stream channel. |
| 158 | */ |
| 159 | void shutdown(); |
| 160 | |
| 161 | // TODO: work in progress. |
| 162 | } |