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