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 | * |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 39 | * @param p4DeviceId P4Runtime-internal device ID |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 40 | * @param pipeconf pipeconf |
| 41 | * @param deviceData target-specific data |
| 42 | * @return completable future, true if the operations was successful, false |
| 43 | * otherwise. |
| 44 | */ |
| 45 | CompletableFuture<Boolean> setPipelineConfig( |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 46 | long p4DeviceId, PiPipeconf pipeconf, ByteBuffer deviceData); |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 47 | |
| 48 | /** |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 49 | * Same as {@link #setPipelineConfig(long, PiPipeconf, ByteBuffer)}, but |
| 50 | * blocks execution. |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 51 | * |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 52 | * @param p4DeviceId P4Runtime-internal device ID |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 53 | * @param pipeconf pipeconf |
| 54 | * @param deviceData target-specific data |
| 55 | * @return true if the operations was successful, false otherwise. |
| 56 | */ |
| 57 | default boolean setPipelineConfigSync( |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 58 | long p4DeviceId, PiPipeconf pipeconf, ByteBuffer deviceData) { |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 59 | checkNotNull(pipeconf); |
| 60 | checkNotNull(deviceData); |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 61 | return Futures.getUnchecked(setPipelineConfig( |
| 62 | p4DeviceId, pipeconf, deviceData)); |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Returns true if the device has the given pipeconf set, false otherwise. |
| 67 | * If possible, equality should be based on {@link PiPipeconf#fingerprint()}, |
| 68 | * otherwise, the implementation can request the server to send the whole |
| 69 | * P4Info and target-specific data for comparison. |
| 70 | * <p> |
| 71 | * This method is expected to return {@code true} if invoked after calling |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 72 | * {@link #setPipelineConfig(long, PiPipeconf, ByteBuffer)} with the same |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 73 | * parameters. |
| 74 | * |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 75 | * @param p4DeviceId P4Runtime-internal device ID |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 76 | * @param pipeconf pipeconf |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 77 | * @return completable future, true if the device has the given pipeconf |
| 78 | * set, false otherwise. |
| 79 | */ |
| 80 | CompletableFuture<Boolean> isPipelineConfigSet( |
Carmelo Cascone | adb8905 | 2019-04-17 20:02:33 -0700 | [diff] [blame] | 81 | long p4DeviceId, PiPipeconf pipeconf); |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 82 | |
| 83 | /** |
Carmelo Cascone | adb8905 | 2019-04-17 20:02:33 -0700 | [diff] [blame] | 84 | * Same as {@link #isPipelineConfigSet(long, PiPipeconf)} but blocks |
| 85 | * execution. |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 86 | * |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 87 | * @param p4DeviceId P4Runtime-internal device ID |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 88 | * @param pipeconf pipeconf |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 89 | * @return true if the device has the given pipeconf set, false otherwise. |
| 90 | */ |
| 91 | default boolean isPipelineConfigSetSync( |
Carmelo Cascone | adb8905 | 2019-04-17 20:02:33 -0700 | [diff] [blame] | 92 | long p4DeviceId, PiPipeconf pipeconf) { |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 93 | return Futures.getUnchecked(isPipelineConfigSet( |
Carmelo Cascone | adb8905 | 2019-04-17 20:02:33 -0700 | [diff] [blame] | 94 | p4DeviceId, pipeconf)); |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 95 | } |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * Returns true if the device has a pipeline config set, false otherwise. |
| 99 | * <p> |
| 100 | * This method is expected to return {@code true} if invoked after |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 101 | * successfully calling {@link #setPipelineConfig(long, PiPipeconf, |
| 102 | * ByteBuffer)} with any parameter. |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 103 | * |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 104 | * @param p4DeviceId P4Runtime-internal device ID |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 105 | * @return completable future, true if the device has a pipeline config set, |
| 106 | * false otherwise. |
| 107 | */ |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 108 | CompletableFuture<Boolean> isAnyPipelineConfigSet(long p4DeviceId); |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 109 | |
| 110 | /** |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 111 | * Same as {@link #isAnyPipelineConfigSet(long)}, but blocks execution. |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 112 | * |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 113 | * @param p4DeviceId P4Runtime-internal device ID |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 114 | * @return true if the device has a pipeline config set, false otherwise. |
| 115 | */ |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 116 | default boolean isAnyPipelineConfigSetSync(long p4DeviceId) { |
| 117 | return Futures.getUnchecked(isAnyPipelineConfigSet(p4DeviceId)); |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 118 | } |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 119 | } |