blob: 03e28c298a8096f306e2c9a02535e353da1cdcad [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
25import java.io.InputStream;
26import java.util.Collection;
27import java.util.concurrent.CompletableFuture;
28
29/**
30 * Client to control a P4Runtime device.
31 */
32@Beta
33public 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 Campanella432f7182017-07-14 18:43:27 +020080 * 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 Casconef7aa3f92017-07-06 23:56:50 -040090 * Shutdown the client by terminating any active RPC such as the stream channel.
91 */
92 void shutdown();
93
94 // TODO: work in progress.
95}