Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.p4runtime.api; |
| 18 | |
| 19 | import org.onosproject.net.pi.model.PiPipeconf; |
| 20 | import org.onosproject.net.pi.runtime.PiPacketOperation; |
| 21 | |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 22 | import java.math.BigInteger; |
| 23 | |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 24 | /** |
| 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 | */ |
| 32 | public interface P4RuntimeStreamClient { |
| 33 | |
| 34 | /** |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 35 | * 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 Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 42 | * <p> |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 43 | * If the server acknowledges this client as master, the {@link |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 44 | * P4RuntimeController} is expected to generate a {@link |
| 45 | * org.onosproject.net.device.DeviceAgentEvent} with type {@link |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 46 | * org.onosproject.net.device.DeviceAgentEvent.Type#ROLE_MASTER}. |
| 47 | * |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 48 | * @param p4DeviceId P4Runtime-internal device ID |
| 49 | * @param master true if we are trying to become master |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 50 | * @param electionId election ID |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 51 | */ |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 52 | void setMastership(long p4DeviceId, boolean master, BigInteger electionId); |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 53 | |
| 54 | /** |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 55 | * Returns true if the StreamChannel RPC is active and hence the P4Runtime |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 56 | * session for the given P4Runtime-internal device ID is open, false |
| 57 | * otherwise. |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 58 | * |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 59 | * @param p4DeviceId P4Runtime-internal device ID |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 60 | * @return boolean |
| 61 | */ |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 62 | boolean isSessionOpen(long p4DeviceId); |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 63 | |
| 64 | /** |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 65 | * Closes the session to the server by terminating the StreamChannel RPC for |
| 66 | * the given P4Runtime-internal device ID. |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 67 | * |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 68 | * @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 Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 77 | * @return boolean |
| 78 | */ |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 79 | boolean isMaster(long p4DeviceId); |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 80 | |
| 81 | /** |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 82 | * Sends a packet-out for the given P4Runtime-internal device ID. |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 83 | * |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 84 | * @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 Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 87 | */ |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 88 | void packetOut(long p4DeviceId, PiPacketOperation packet, PiPipeconf pipeconf); |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 89 | } |