Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 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; |
| 21 | import org.onosproject.net.pi.runtime.PiPacketOperation; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 22 | import org.onosproject.net.pi.runtime.PiTableEntry; |
| 23 | import org.onosproject.net.pi.runtime.PiTableId; |
| 24 | |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 25 | import java.util.Collection; |
| 26 | import java.util.concurrent.CompletableFuture; |
| 27 | |
| 28 | /** |
| 29 | * Client to control a P4Runtime device. |
| 30 | */ |
| 31 | @Beta |
| 32 | public interface P4RuntimeClient { |
| 33 | |
| 34 | /** |
| 35 | * Type of write operation. |
| 36 | */ |
| 37 | enum WriteOperationType { |
| 38 | UNSPECIFIED, |
| 39 | INSERT, |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame^] | 40 | MODIFY, |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 41 | DELETE |
| 42 | } |
| 43 | |
| 44 | /** |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame^] | 45 | * Sets the pipeline configuration defined by the given pipeconf for the given target-specific configuration |
| 46 | * extension type (e.g. {@link PiPipeconf.ExtensionType#BMV2_JSON}, or {@link PiPipeconf.ExtensionType#TOFINO_BIN}). |
| 47 | * This method should be called before any other method of this client. |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 48 | * |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame^] | 49 | * @param pipeconf pipeconf |
| 50 | * @param targetConfigExtType extension type of the target-specific configuration |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 51 | * @return a completable future of a boolean, true if the operations was successful, false otherwise. |
| 52 | */ |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame^] | 53 | CompletableFuture<Boolean> setPipelineConfig(PiPipeconf pipeconf, PiPipeconf.ExtensionType targetConfigExtType); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Initializes the stream channel, after which all messages received from the device will be notified using the |
| 57 | * {@link P4RuntimeController} event listener. |
| 58 | * |
| 59 | * @return a completable future of a boolean, true if the operations was successful, false otherwise. |
| 60 | */ |
| 61 | CompletableFuture<Boolean> initStreamChannel(); |
| 62 | |
| 63 | /** |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame^] | 64 | * Performs the given write operation for the given table entries and pipeconf. |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 65 | * |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame^] | 66 | * @param entries table entries |
| 67 | * @param opType operation type |
| 68 | * @param pipeconf pipeconf currently deployed on the device |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 69 | * @return true if the operation was successful, false otherwise. |
| 70 | */ |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame^] | 71 | CompletableFuture<Boolean> writeTableEntries(Collection<PiTableEntry> entries, WriteOperationType opType, |
| 72 | PiPipeconf pipeconf); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * Dumps all entries currently installed in the given table. |
| 76 | * |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame^] | 77 | * @param tableId table identifier |
| 78 | * @param pipeconf pipeconf currently deployed on the device |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 79 | * @return completable future of a collection of table entries |
| 80 | */ |
Carmelo Cascone | 8d99b17 | 2017-07-18 17:26:31 -0400 | [diff] [blame^] | 81 | CompletableFuture<Collection<PiTableEntry>> dumpTable(PiTableId tableId, PiPipeconf pipeconf); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 82 | |
| 83 | /** |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 84 | * Executes a packet-out operation. |
| 85 | * |
| 86 | * @param packet packet-out operation to be performed by the device |
| 87 | * @param pipeconf pipeconf currently deployed on the device |
| 88 | * @return a completable future of a boolean, true if the operations was successful, false otherwise. |
| 89 | */ |
| 90 | CompletableFuture<Boolean> packetOut(PiPacketOperation packet, PiPipeconf pipeconf); |
| 91 | |
Andrea Campanella | 432f718 | 2017-07-14 18:43:27 +0200 | [diff] [blame] | 92 | /** |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 93 | * Shutdown the client by terminating any active RPC such as the stream channel. |
| 94 | */ |
| 95 | void shutdown(); |
| 96 | |
| 97 | // TODO: work in progress. |
| 98 | } |