blob: 3ef6843cae222c9070a1c0706b7762f5f43272c2 [file] [log] [blame]
Carmelo Cascone4c289b72019-01-22 15:30:45 -08001/*
2 * Copyright 2019-present Open Networking Foundation
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 org.onosproject.net.pi.model.PiPipeconf;
20import org.onosproject.net.pi.runtime.PiPacketOperation;
21
Carmelo Cascone3977ea42019-02-28 13:43:42 -080022import java.math.BigInteger;
23
Carmelo Cascone4c289b72019-01-22 15:30:45 -080024/**
25 * P4Runtime client interface for the StreamChannel RPC. It allows management of
26 * the P4Runtime session (open/close, mastership arbitration) as well as sending
27 * packet-outs. All messages received from the server via the stream channel,
28 * such as master arbitration updates, or packet-ins, are handled by the
29 * P4RuntimeController. Anyone interested in those messages should register a
30 * listener with the latter.
31 */
32public interface P4RuntimeStreamClient {
33
34 /**
Carmelo Casconec2be50a2019-04-10 00:15:39 -070035 * Opportunistically opens a session with the server for the given
36 * P4Runtime-internal device ID by starting a StreamChannel RPC and sending
37 * a {@code MasterArbitrationUpdate} message with the given election ID. The
38 * {@code master} boolean flag is used to indicated if we are trying to
39 * became master or not. If false, the implementation might delay sending
40 * the {@code MasterArbitrationUpdate} message until another node becomes
41 * master with a higher election ID.
Carmelo Cascone4c289b72019-01-22 15:30:45 -080042 * <p>
Carmelo Cascone3977ea42019-02-28 13:43:42 -080043 * If the server acknowledges this client as master, the {@link
Carmelo Cascone4c289b72019-01-22 15:30:45 -080044 * P4RuntimeController} is expected to generate a {@link
45 * org.onosproject.net.device.DeviceAgentEvent} with type {@link
Carmelo Cascone3977ea42019-02-28 13:43:42 -080046 * org.onosproject.net.device.DeviceAgentEvent.Type#ROLE_MASTER}.
47 *
Carmelo Casconec2be50a2019-04-10 00:15:39 -070048 * @param p4DeviceId P4Runtime-internal device ID
49 * @param master true if we are trying to become master
Carmelo Cascone3977ea42019-02-28 13:43:42 -080050 * @param electionId election ID
Carmelo Cascone4c289b72019-01-22 15:30:45 -080051 */
Carmelo Casconec2be50a2019-04-10 00:15:39 -070052 void setMastership(long p4DeviceId, boolean master, BigInteger electionId);
Carmelo Cascone4c289b72019-01-22 15:30:45 -080053
54 /**
Carmelo Cascone3977ea42019-02-28 13:43:42 -080055 * Returns true if the StreamChannel RPC is active and hence the P4Runtime
Carmelo Casconec2be50a2019-04-10 00:15:39 -070056 * session for the given P4Runtime-internal device ID is open, false
57 * otherwise.
Carmelo Cascone4c289b72019-01-22 15:30:45 -080058 *
Carmelo Casconec2be50a2019-04-10 00:15:39 -070059 * @param p4DeviceId P4Runtime-internal device ID
Carmelo Cascone4c289b72019-01-22 15:30:45 -080060 * @return boolean
61 */
Carmelo Casconec2be50a2019-04-10 00:15:39 -070062 boolean isSessionOpen(long p4DeviceId);
Carmelo Cascone4c289b72019-01-22 15:30:45 -080063
64 /**
Carmelo Casconec2be50a2019-04-10 00:15:39 -070065 * Closes the session to the server by terminating the StreamChannel RPC for
66 * the given P4Runtime-internal device ID.
Carmelo Cascone4c289b72019-01-22 15:30:45 -080067 *
Carmelo Casconec2be50a2019-04-10 00:15:39 -070068 * @param p4DeviceId P4Runtime-internal device ID
69 */
70 void closeSession(long p4DeviceId);
71
72 /**
73 * Returns true if this client is master for the given P4Runtime-internal
74 * device ID, false otherwise.
75 *
76 * @param p4DeviceId P4Runtime-internal device ID
Carmelo Cascone4c289b72019-01-22 15:30:45 -080077 * @return boolean
78 */
Carmelo Casconec2be50a2019-04-10 00:15:39 -070079 boolean isMaster(long p4DeviceId);
Carmelo Cascone4c289b72019-01-22 15:30:45 -080080
81 /**
Carmelo Casconec2be50a2019-04-10 00:15:39 -070082 * Sends a packet-out for the given P4Runtime-internal device ID.
Carmelo Cascone4c289b72019-01-22 15:30:45 -080083 *
Carmelo Casconec2be50a2019-04-10 00:15:39 -070084 * @param p4DeviceId P4Runtime-internal device ID
85 * @param packet packet-out operation to be performed by the device
86 * @param pipeconf pipeconf currently deployed on the device
Carmelo Cascone4c289b72019-01-22 15:30:45 -080087 */
Carmelo Casconec2be50a2019-04-10 00:15:39 -070088 void packetOut(long p4DeviceId, PiPacketOperation packet, PiPipeconf pipeconf);
Carmelo Cascone4c289b72019-01-22 15:30:45 -080089}