blob: 7ecbd80dbf5b4648d784e0625f117a56005ae563 [file] [log] [blame]
Carmelo Casconef7aa3f92017-07-06 23:56:50 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Carmelo Casconef7aa3f92017-07-06 23:56:50 -04003 *
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;
Carmelo Cascone87b9b392017-10-02 18:33:20 +020021import org.onosproject.net.pi.runtime.PiActionGroup;
Carmelo Cascone87892e22017-11-13 16:01:29 -080022import org.onosproject.net.pi.model.PiActionProfileId;
Carmelo Casconeb045ddc2017-09-01 01:26:35 +020023import org.onosproject.net.pi.runtime.PiCounterCellData;
24import org.onosproject.net.pi.runtime.PiCounterCellId;
Carmelo Cascone87892e22017-11-13 16:01:29 -080025import org.onosproject.net.pi.model.PiCounterId;
Andrea Campanella432f7182017-07-14 18:43:27 +020026import org.onosproject.net.pi.runtime.PiPacketOperation;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040027import org.onosproject.net.pi.runtime.PiTableEntry;
Carmelo Cascone87892e22017-11-13 16:01:29 -080028import org.onosproject.net.pi.model.PiTableId;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040029
Carmelo Casconed61fdb32017-10-30 10:09:57 -070030import java.nio.ByteBuffer;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040031import java.util.Collection;
Carmelo Casconeb045ddc2017-09-01 01:26:35 +020032import java.util.Set;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040033import java.util.concurrent.CompletableFuture;
34
35/**
36 * Client to control a P4Runtime device.
37 */
38@Beta
39public interface P4RuntimeClient {
40
41 /**
42 * Type of write operation.
43 */
44 enum WriteOperationType {
45 UNSPECIFIED,
46 INSERT,
Carmelo Cascone8d99b172017-07-18 17:26:31 -040047 MODIFY,
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040048 DELETE
49 }
50
51 /**
Carmelo Casconed61fdb32017-10-30 10:09:57 -070052 * Sets the device pipeline according to the given pipeconf, and for the given byte buffer representing the
53 * target-specific data to be used in the P4Runtime's SetPipelineConfig message. This method should be called
54 * before any other method of this client.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040055 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -070056 * @param pipeconf pipeconf
57 * @param deviceData target-specific data
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040058 * @return a completable future of a boolean, true if the operations was successful, false otherwise.
59 */
Carmelo Casconed61fdb32017-10-30 10:09:57 -070060 CompletableFuture<Boolean> setPipelineConfig(PiPipeconf pipeconf, ByteBuffer deviceData);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040061
62 /**
63 * Initializes the stream channel, after which all messages received from the device will be notified using the
64 * {@link P4RuntimeController} event listener.
65 *
66 * @return a completable future of a boolean, true if the operations was successful, false otherwise.
67 */
68 CompletableFuture<Boolean> initStreamChannel();
69
70 /**
Carmelo Cascone8d99b172017-07-18 17:26:31 -040071 * Performs the given write operation for the given table entries and pipeconf.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040072 *
Carmelo Cascone8d99b172017-07-18 17:26:31 -040073 * @param entries table entries
74 * @param opType operation type
75 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040076 * @return true if the operation was successful, false otherwise.
77 */
Carmelo Cascone8d99b172017-07-18 17:26:31 -040078 CompletableFuture<Boolean> writeTableEntries(Collection<PiTableEntry> entries, WriteOperationType opType,
79 PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040080
81 /**
Carmelo Casconeb045ddc2017-09-01 01:26:35 +020082 * Dumps all entries currently installed in the given table, for the given pipeconf.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040083 *
Carmelo Cascone8d99b172017-07-18 17:26:31 -040084 * @param tableId table identifier
85 * @param pipeconf pipeconf currently deployed on the device
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040086 * @return completable future of a collection of table entries
87 */
Carmelo Cascone8d99b172017-07-18 17:26:31 -040088 CompletableFuture<Collection<PiTableEntry>> dumpTable(PiTableId tableId, PiPipeconf pipeconf);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040089
90 /**
Carmelo Casconeb045ddc2017-09-01 01:26:35 +020091 * Executes a packet-out operation for the given pipeconf.
Andrea Campanella432f7182017-07-14 18:43:27 +020092 *
93 * @param packet packet-out operation to be performed by the device
94 * @param pipeconf pipeconf currently deployed on the device
95 * @return a completable future of a boolean, true if the operations was successful, false otherwise.
96 */
97 CompletableFuture<Boolean> packetOut(PiPacketOperation packet, PiPipeconf pipeconf);
98
Andrea Campanella432f7182017-07-14 18:43:27 +020099 /**
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200100 * Returns the value of all counter cells for the given set of counter identifiers and pipeconf.
101 *
102 * @param counterIds counter identifiers
103 * @param pipeconf pipeconf
104 * @return collection of counter data
105 */
106 CompletableFuture<Collection<PiCounterCellData>> readAllCounterCells(Set<PiCounterId> counterIds,
107 PiPipeconf pipeconf);
108
109 /**
110 * Returns a collection of counter data corresponding to the given set of counter cell identifiers, for the given
111 * pipeconf.
112 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700113 * @param cellIds set of counter cell identifiers
114 * @param pipeconf pipeconf
Carmelo Casconeb045ddc2017-09-01 01:26:35 +0200115 * @return collection of counter data
116 */
117 CompletableFuture<Collection<PiCounterCellData>> readCounterCells(Set<PiCounterCellId> cellIds,
118 PiPipeconf pipeconf);
119
120 /**
Yi Tseng82512da2017-08-16 19:46:36 -0700121 * Performs the given write operation for the given action group members and pipeconf.
122 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700123 * @param group action group
124 * @param opType write operation type
Yi Tseng82512da2017-08-16 19:46:36 -0700125 * @param pipeconf the pipeconf currently deployed on the device
126 * @return true if the operation was successful, false otherwise
127 */
128 CompletableFuture<Boolean> writeActionGroupMembers(PiActionGroup group,
Yi Tseng82512da2017-08-16 19:46:36 -0700129 WriteOperationType opType,
130 PiPipeconf pipeconf);
131
132 /**
133 * Performs the given write operation for the given action group and pipeconf.
134 *
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700135 * @param group the action group
136 * @param opType write operation type
Yi Tseng82512da2017-08-16 19:46:36 -0700137 * @param pipeconf the pipeconf currently deployed on the device
138 * @return true if the operation was successful, false otherwise
139 */
140 CompletableFuture<Boolean> writeActionGroup(PiActionGroup group,
141 WriteOperationType opType,
142 PiPipeconf pipeconf);
143
144 /**
145 * Dumps all groups currently installed for the given action profile.
146 *
147 * @param actionProfileId the action profile id
Carmelo Casconed61fdb32017-10-30 10:09:57 -0700148 * @param pipeconf the pipeconf currently deployed on the device
Yi Tseng82512da2017-08-16 19:46:36 -0700149 * @return completable future of a collection of groups
150 */
151 CompletableFuture<Collection<PiActionGroup>> dumpGroups(PiActionProfileId actionProfileId,
152 PiPipeconf pipeconf);
153
154 /**
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400155 * Shutdown the client by terminating any active RPC such as the stream channel.
156 */
157 void shutdown();
158
Yi Tseng3e7f1452017-10-20 10:31:53 -0700159 /**
160 * Sends a master arbitration update to the device.
161 *
162 * @return a completable future containing true if the operation was successful; false otherwise
163 */
164 CompletableFuture<Boolean> sendMasterArbitrationUpdate();
165
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400166 // TODO: work in progress.
167}