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 | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame^] | 35 | * 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 Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 41 | * <p> |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame^] | 42 | * If the server acknowledges this client as master, the {@link |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 43 | * P4RuntimeController} is expected to generate a {@link |
| 44 | * org.onosproject.net.device.DeviceAgentEvent} with type {@link |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame^] | 45 | * 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 Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 49 | */ |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame^] | 50 | void setMastership(boolean master, BigInteger electionId); |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 51 | |
| 52 | /** |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame^] | 53 | * Returns true if the StreamChannel RPC is active and hence the P4Runtime |
| 54 | * session is open, false otherwise. |
Carmelo Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 55 | * |
| 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 Cascone | 4c289b7 | 2019-01-22 15:30:45 -0800 | [diff] [blame] | 66 | * 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 | } |