blob: 555f906b78d6c10bcd945707870cbf761bfc183a [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 Cascone3977ea42019-02-28 13:43:42 -080035 * Opportunistically opens a session with the server by starting a
36 * StreamChannel RPC and sends a {@code MasterArbitrationUpdate} message
37 * with the given election ID. The {@code master} boolean flag is used to
38 * indicated if we are trying to became master or not. If false, the
39 * implementation might delay sending the {@code MasterArbitrationUpdate}
40 * message until another node becomes master with a higher election ID.
Carmelo Cascone4c289b72019-01-22 15:30:45 -080041 * <p>
Carmelo Cascone3977ea42019-02-28 13:43:42 -080042 * If the server acknowledges this client as master, the {@link
Carmelo Cascone4c289b72019-01-22 15:30:45 -080043 * P4RuntimeController} is expected to generate a {@link
44 * org.onosproject.net.device.DeviceAgentEvent} with type {@link
Carmelo Cascone3977ea42019-02-28 13:43:42 -080045 * org.onosproject.net.device.DeviceAgentEvent.Type#ROLE_MASTER}.
46 *
47 * @param master true if we are trying to become master
48 * @param electionId election ID
Carmelo Cascone4c289b72019-01-22 15:30:45 -080049 */
Carmelo Cascone3977ea42019-02-28 13:43:42 -080050 void setMastership(boolean master, BigInteger electionId);
Carmelo Cascone4c289b72019-01-22 15:30:45 -080051
52 /**
Carmelo Cascone3977ea42019-02-28 13:43:42 -080053 * Returns true if the StreamChannel RPC is active and hence the P4Runtime
54 * session is open, false otherwise.
Carmelo Cascone4c289b72019-01-22 15:30:45 -080055 *
56 * @return boolean
57 */
58 boolean isSessionOpen();
59
60 /**
61 * Closes the session to the server by terminating the Stream RPC.
62 */
63 void closeSession();
64
65 /**
Carmelo Cascone4c289b72019-01-22 15:30:45 -080066 * Returns true if this client is master for the server, false otherwise.
67 *
68 * @return boolean
69 */
70 boolean isMaster();
71
72 /**
73 * Sends a packet-out for the given pipeconf.
74 *
75 * @param packet packet-out operation to be performed by the device
76 * @param pipeconf pipeconf currently deployed on the device
77 */
78 void packetOut(PiPacketOperation packet, PiPipeconf pipeconf);
79}