blob: 3b7f3d307578cd4e2ad3ef04bc86a396351c2935 [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;
Yi Tseng82512da2017-08-16 19:46:36 -070021import org.onosproject.net.pi.runtime.PiActionProfileId;
Carmelo Casconeb045ddc2017-09-01 01:26:35 +020022import org.onosproject.net.pi.runtime.PiCounterCellData;
23import org.onosproject.net.pi.runtime.PiCounterCellId;
24import org.onosproject.net.pi.runtime.PiCounterId;
Yi Tseng82512da2017-08-16 19:46:36 -070025import org.onosproject.net.pi.runtime.PiActionGroup;
26import org.onosproject.net.pi.runtime.PiActionGroupMember;
Andrea Campanella432f7182017-07-14 18:43:27 +020027import org.onosproject.net.pi.runtime.PiPacketOperation;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040028import org.onosproject.net.pi.runtime.PiTableEntry;
29import org.onosproject.net.pi.runtime.PiTableId;
30
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 Cascone8d99b172017-07-18 17:26:31 -040052 * Sets the pipeline configuration defined by the given pipeconf for the given target-specific configuration
53 * extension type (e.g. {@link PiPipeconf.ExtensionType#BMV2_JSON}, or {@link PiPipeconf.ExtensionType#TOFINO_BIN}).
54 * This method should be called before any other method of this client.
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040055 *
Carmelo Cascone8d99b172017-07-18 17:26:31 -040056 * @param pipeconf pipeconf
57 * @param targetConfigExtType extension type of the target-specific configuration
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 Cascone8d99b172017-07-18 17:26:31 -040060 CompletableFuture<Boolean> setPipelineConfig(PiPipeconf pipeconf, PiPipeconf.ExtensionType targetConfigExtType);
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 *
113 * @param cellIds set of counter cell identifiers
114 * @param pipeconf pipeconf
115 * @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 *
123 * @param group action group
124 * @param members the collection of action group members
125 * @param opType write operation type
126 * @param pipeconf the pipeconf currently deployed on the device
127 * @return true if the operation was successful, false otherwise
128 */
129 CompletableFuture<Boolean> writeActionGroupMembers(PiActionGroup group,
130 Collection<PiActionGroupMember> members,
131 WriteOperationType opType,
132 PiPipeconf pipeconf);
133
134 /**
135 * Performs the given write operation for the given action group and pipeconf.
136 *
137 * @param group the action group
138 * @param opType write operation type
139 * @param pipeconf the pipeconf currently deployed on the device
140 * @return true if the operation was successful, false otherwise
141 */
142 CompletableFuture<Boolean> writeActionGroup(PiActionGroup group,
143 WriteOperationType opType,
144 PiPipeconf pipeconf);
145
146 /**
147 * Dumps all groups currently installed for the given action profile.
148 *
149 * @param actionProfileId the action profile id
150 * @param pipeconf the pipeconf currently deployed on the device
151 * @return completable future of a collection of groups
152 */
153 CompletableFuture<Collection<PiActionGroup>> dumpGroups(PiActionProfileId actionProfileId,
154 PiPipeconf pipeconf);
155
156 /**
Carmelo Casconef7aa3f92017-07-06 23:56:50 -0400157 * Shutdown the client by terminating any active RPC such as the stream channel.
158 */
159 void shutdown();
160
161 // TODO: work in progress.
162}