blob: 2418a78ffa831743c305afd747eebe92316be5fe [file] [log] [blame]
Carmelo Casconef7aa3f92017-07-06 23:56:50 -04001/*
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
17package org.onosproject.p4runtime.api;
18
19import com.google.common.annotations.Beta;
Andrea Campanella432f7182017-07-14 18:43:27 +020020import org.onosproject.net.pi.model.PiPipeconf;
21import org.onosproject.net.pi.runtime.PiPacketOperation;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040022import org.onosproject.net.pi.runtime.PiTableEntry;
23import org.onosproject.net.pi.runtime.PiTableId;
24
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040025import java.util.Collection;
26import java.util.concurrent.CompletableFuture;
27
28/**
29 * Client to control a P4Runtime device.
30 */
31@Beta
32public interface P4RuntimeClient {
33
34 /**
35 * Type of write operation.
36 */
37 enum WriteOperationType {
38 UNSPECIFIED,
39 INSERT,
Carmelo Cascone8d99b172017-07-18 17:26:31 -040040 MODIFY,
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040041 DELETE
42 }
43
44 /**
Carmelo Cascone8d99b172017-07-18 17:26:31 -040045 * 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 Casconef7aa3f92017-07-06 23:56:50 -040048 *
Carmelo Cascone8d99b172017-07-18 17:26:31 -040049 * @param pipeconf pipeconf
50 * @param targetConfigExtType extension type of the target-specific configuration
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040051 * @return a completable future of a boolean, true if the operations was successful, false otherwise.
52 */
Carmelo Cascone8d99b172017-07-18 17:26:31 -040053 CompletableFuture<Boolean> setPipelineConfig(PiPipeconf pipeconf, PiPipeconf.ExtensionType targetConfigExtType);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040054
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 Cascone8d99b172017-07-18 17:26:31 -040064 * Performs the given write operation for the given table entries and pipeconf.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040065 *
Carmelo Cascone8d99b172017-07-18 17:26:31 -040066 * @param entries table entries
67 * @param opType operation type
68 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040069 * @return true if the operation was successful, false otherwise.
70 */
Carmelo Cascone8d99b172017-07-18 17:26:31 -040071 CompletableFuture<Boolean> writeTableEntries(Collection<PiTableEntry> entries, WriteOperationType opType,
72 PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040073
74 /**
75 * Dumps all entries currently installed in the given table.
76 *
Carmelo Cascone8d99b172017-07-18 17:26:31 -040077 * @param tableId table identifier
78 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040079 * @return completable future of a collection of table entries
80 */
Carmelo Cascone8d99b172017-07-18 17:26:31 -040081 CompletableFuture<Collection<PiTableEntry>> dumpTable(PiTableId tableId, PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040082
83 /**
Andrea Campanella432f7182017-07-14 18:43:27 +020084 * 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 Campanella432f7182017-07-14 18:43:27 +020092 /**
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040093 * Shutdown the client by terminating any active RPC such as the stream channel.
94 */
95 void shutdown();
96
97 // TODO: work in progress.
98}