Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-present Open Networking Foundation |
| 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.util.concurrent.Futures; |
| 20 | import org.onosproject.net.pi.model.PiPipeconf; |
| 21 | |
| 22 | import java.nio.ByteBuffer; |
| 23 | import java.util.concurrent.CompletableFuture; |
| 24 | |
| 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | |
| 27 | /** |
| 28 | * P4Runtime client interface for the pipeline configuration-related RPCs. |
| 29 | */ |
| 30 | public interface P4RuntimePipelineConfigClient { |
| 31 | |
| 32 | /** |
| 33 | * Uploads and commit a pipeline configuration to the server using the |
| 34 | * {@link PiPipeconf.ExtensionType#P4_INFO_TEXT} extension of the given |
| 35 | * pipeconf, and the given byte buffer as the target-specific data ("P4 |
| 36 | * blob") to be used in the P4Runtime's {@code SetPipelineConfig} message. |
| 37 | * Returns true if the operations was successful, false otherwise. |
| 38 | * |
| 39 | * @param pipeconf pipeconf |
| 40 | * @param deviceData target-specific data |
| 41 | * @return completable future, true if the operations was successful, false |
| 42 | * otherwise. |
| 43 | */ |
| 44 | CompletableFuture<Boolean> setPipelineConfig( |
| 45 | PiPipeconf pipeconf, ByteBuffer deviceData); |
| 46 | |
| 47 | /** |
| 48 | * Same as {@link #setPipelineConfig(PiPipeconf, ByteBuffer)}, but blocks |
| 49 | * execution. |
| 50 | * |
| 51 | * @param pipeconf pipeconf |
| 52 | * @param deviceData target-specific data |
| 53 | * @return true if the operations was successful, false otherwise. |
| 54 | */ |
| 55 | default boolean setPipelineConfigSync( |
| 56 | PiPipeconf pipeconf, ByteBuffer deviceData) { |
| 57 | checkNotNull(pipeconf); |
| 58 | checkNotNull(deviceData); |
| 59 | return Futures.getUnchecked(setPipelineConfig(pipeconf, deviceData)); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Returns true if the device has the given pipeconf set, false otherwise. |
| 64 | * If possible, equality should be based on {@link PiPipeconf#fingerprint()}, |
| 65 | * otherwise, the implementation can request the server to send the whole |
| 66 | * P4Info and target-specific data for comparison. |
| 67 | * <p> |
| 68 | * This method is expected to return {@code true} if invoked after calling |
| 69 | * {@link #setPipelineConfig(PiPipeconf, ByteBuffer)} with the same |
| 70 | * parameters. |
| 71 | * |
| 72 | * @param pipeconf pipeconf |
| 73 | * @param deviceData target-specific data |
| 74 | * @return completable future, true if the device has the given pipeconf |
| 75 | * set, false otherwise. |
| 76 | */ |
| 77 | CompletableFuture<Boolean> isPipelineConfigSet( |
| 78 | PiPipeconf pipeconf, ByteBuffer deviceData); |
| 79 | |
| 80 | /** |
| 81 | * Same as {@link #isPipelineConfigSet(PiPipeconf, ByteBuffer)} but blocks |
| 82 | * execution. |
| 83 | * |
| 84 | * @param pipeconf pipeconf |
| 85 | * @param deviceData target-specific data |
| 86 | * @return true if the device has the given pipeconf set, false otherwise. |
| 87 | */ |
| 88 | default boolean isPipelineConfigSetSync( |
| 89 | PiPipeconf pipeconf, ByteBuffer deviceData) { |
| 90 | return Futures.getUnchecked(isPipelineConfigSet(pipeconf, deviceData)); |
| 91 | } |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame^] | 92 | |
| 93 | /** |
| 94 | * Returns true if the device has a pipeline config set, false otherwise. |
| 95 | * <p> |
| 96 | * This method is expected to return {@code true} if invoked after |
| 97 | * successfully calling {@link #setPipelineConfig(PiPipeconf, ByteBuffer)} |
| 98 | * with any parameter. |
| 99 | * |
| 100 | * @return completable future, true if the device has a pipeline config set, |
| 101 | * false otherwise. |
| 102 | */ |
| 103 | CompletableFuture<Boolean> isAnyPipelineConfigSet(); |
| 104 | |
| 105 | /** |
| 106 | * Same as {@link #isAnyPipelineConfigSet()}, but blocks execution. |
| 107 | * |
| 108 | * @return true if the device has a pipeline config set, false otherwise. |
| 109 | */ |
| 110 | default boolean isAnyPipelineConfigSetSync() { |
| 111 | return Futures.getUnchecked(isAnyPipelineConfigSet()); |
| 112 | } |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 113 | } |