blob: cc4b9e13583a1ac5d5832f96271faf882960cb75 [file] [log] [blame]
Carmelo Cascone4c289b72019-01-22 15:30:45 -08001/*
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
17package org.onosproject.p4runtime.api;
18
19import com.google.common.util.concurrent.Futures;
20import org.onosproject.net.pi.model.PiPipeconf;
21
22import java.nio.ByteBuffer;
23import java.util.concurrent.CompletableFuture;
24
25import static com.google.common.base.Preconditions.checkNotNull;
26
27/**
28 * P4Runtime client interface for the pipeline configuration-related RPCs.
29 */
30public 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 Casconec2be50a2019-04-10 00:15:39 -070039 * @param p4DeviceId P4Runtime-internal device ID
Carmelo Cascone4c289b72019-01-22 15:30:45 -080040 * @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 Casconec2be50a2019-04-10 00:15:39 -070046 long p4DeviceId, PiPipeconf pipeconf, ByteBuffer deviceData);
Carmelo Cascone4c289b72019-01-22 15:30:45 -080047
48 /**
Carmelo Casconec2be50a2019-04-10 00:15:39 -070049 * Same as {@link #setPipelineConfig(long, PiPipeconf, ByteBuffer)}, but
50 * blocks execution.
Carmelo Cascone4c289b72019-01-22 15:30:45 -080051 *
Carmelo Casconec2be50a2019-04-10 00:15:39 -070052 * @param p4DeviceId P4Runtime-internal device ID
Carmelo Cascone4c289b72019-01-22 15:30:45 -080053 * @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 Casconec2be50a2019-04-10 00:15:39 -070058 long p4DeviceId, PiPipeconf pipeconf, ByteBuffer deviceData) {
Carmelo Cascone4c289b72019-01-22 15:30:45 -080059 checkNotNull(pipeconf);
60 checkNotNull(deviceData);
Carmelo Casconec2be50a2019-04-10 00:15:39 -070061 return Futures.getUnchecked(setPipelineConfig(
62 p4DeviceId, pipeconf, deviceData));
Carmelo Cascone4c289b72019-01-22 15:30:45 -080063 }
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 Casconec2be50a2019-04-10 00:15:39 -070072 * {@link #setPipelineConfig(long, PiPipeconf, ByteBuffer)} with the same
Carmelo Cascone4c289b72019-01-22 15:30:45 -080073 * parameters.
74 *
Carmelo Casconec2be50a2019-04-10 00:15:39 -070075 * @param p4DeviceId P4Runtime-internal device ID
Carmelo Cascone4c289b72019-01-22 15:30:45 -080076 * @param pipeconf pipeconf
Carmelo Cascone4c289b72019-01-22 15:30:45 -080077 * @return completable future, true if the device has the given pipeconf
78 * set, false otherwise.
79 */
80 CompletableFuture<Boolean> isPipelineConfigSet(
Carmelo Casconeadb89052019-04-17 20:02:33 -070081 long p4DeviceId, PiPipeconf pipeconf);
Carmelo Cascone4c289b72019-01-22 15:30:45 -080082
83 /**
Carmelo Casconeadb89052019-04-17 20:02:33 -070084 * Same as {@link #isPipelineConfigSet(long, PiPipeconf)} but blocks
85 * execution.
Carmelo Cascone4c289b72019-01-22 15:30:45 -080086 *
Carmelo Casconec2be50a2019-04-10 00:15:39 -070087 * @param p4DeviceId P4Runtime-internal device ID
Carmelo Cascone4c289b72019-01-22 15:30:45 -080088 * @param pipeconf pipeconf
Carmelo Cascone4c289b72019-01-22 15:30:45 -080089 * @return true if the device has the given pipeconf set, false otherwise.
90 */
91 default boolean isPipelineConfigSetSync(
Carmelo Casconeadb89052019-04-17 20:02:33 -070092 long p4DeviceId, PiPipeconf pipeconf) {
Carmelo Casconec2be50a2019-04-10 00:15:39 -070093 return Futures.getUnchecked(isPipelineConfigSet(
Carmelo Casconeadb89052019-04-17 20:02:33 -070094 p4DeviceId, pipeconf));
Carmelo Cascone4c289b72019-01-22 15:30:45 -080095 }
Carmelo Cascone3977ea42019-02-28 13:43:42 -080096
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 Casconec2be50a2019-04-10 00:15:39 -0700101 * successfully calling {@link #setPipelineConfig(long, PiPipeconf,
102 * ByteBuffer)} with any parameter.
Carmelo Cascone3977ea42019-02-28 13:43:42 -0800103 *
Carmelo Casconec2be50a2019-04-10 00:15:39 -0700104 * @param p4DeviceId P4Runtime-internal device ID
Carmelo Cascone3977ea42019-02-28 13:43:42 -0800105 * @return completable future, true if the device has a pipeline config set,
106 * false otherwise.
107 */
Carmelo Casconec2be50a2019-04-10 00:15:39 -0700108 CompletableFuture<Boolean> isAnyPipelineConfigSet(long p4DeviceId);
Carmelo Cascone3977ea42019-02-28 13:43:42 -0800109
110 /**
Carmelo Casconec2be50a2019-04-10 00:15:39 -0700111 * Same as {@link #isAnyPipelineConfigSet(long)}, but blocks execution.
Carmelo Cascone3977ea42019-02-28 13:43:42 -0800112 *
Carmelo Casconec2be50a2019-04-10 00:15:39 -0700113 * @param p4DeviceId P4Runtime-internal device ID
Carmelo Cascone3977ea42019-02-28 13:43:42 -0800114 * @return true if the device has a pipeline config set, false otherwise.
115 */
Carmelo Casconec2be50a2019-04-10 00:15:39 -0700116 default boolean isAnyPipelineConfigSetSync(long p4DeviceId) {
117 return Futures.getUnchecked(isAnyPipelineConfigSet(p4DeviceId));
Carmelo Cascone3977ea42019-02-28 13:43:42 -0800118 }
Carmelo Cascone4c289b72019-01-22 15:30:45 -0800119}