blob: ee622cba4cfbc07529347996cd4b2d1734c8f554 [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;
20import org.onosproject.net.pi.runtime.PiTableEntry;
21import org.onosproject.net.pi.runtime.PiTableId;
22
23import java.io.InputStream;
24import java.util.Collection;
25import java.util.concurrent.CompletableFuture;
26
27/**
28 * Client to control a P4Runtime device.
29 */
30@Beta
31public interface P4RuntimeClient {
32
33 /**
34 * Type of write operation.
35 */
36 enum WriteOperationType {
37 UNSPECIFIED,
38 INSERT,
39 UPDATE,
40 DELETE
41 }
42
43 /**
44 * Sets the pipeline configuration. This method should be called before any other method of this client.
45 *
46 * @param p4Info input stream of a P4Info message in text format
47 * @param targetConfig input stream of the target-specific configuration (e.g. BMv2 JSON)
48 * @return a completable future of a boolean, true if the operations was successful, false otherwise.
49 */
50 CompletableFuture<Boolean> setPipelineConfig(InputStream p4Info, InputStream targetConfig);
51
52 /**
53 * Initializes the stream channel, after which all messages received from the device will be notified using the
54 * {@link P4RuntimeController} event listener.
55 *
56 * @return a completable future of a boolean, true if the operations was successful, false otherwise.
57 */
58 CompletableFuture<Boolean> initStreamChannel();
59
60 /**
61 * Performs the given write operation for the given table entries.
62 *
63 * @param entries table entries
64 * @param opType operation type.
65 * @return true if the operation was successful, false otherwise.
66 */
67 boolean writeTableEntries(Collection<PiTableEntry> entries, WriteOperationType opType);
68
69 /**
70 * Dumps all entries currently installed in the given table.
71 *
72 * @param tableId table identifier
73 * @return completable future of a collection of table entries
74 */
75 CompletableFuture<Collection<PiTableEntry>> dumpTable(PiTableId tableId);
76
77 /**
78 * Shutdown the client by terminating any active RPC such as the stream channel.
79 */
80 void shutdown();
81
82 // TODO: work in progress.
83}