Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 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 com.google.common.annotations.Beta; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 20 | import org.onosproject.event.ListenerService; |
| 21 | import org.onosproject.net.DeviceId; |
Andrea Campanella | 1e57344 | 2018-05-17 17:07:13 +0200 | [diff] [blame] | 22 | import org.onosproject.net.device.ChannelListener; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Controller of P4Runtime devices. |
| 26 | */ |
| 27 | @Beta |
| 28 | public interface P4RuntimeController extends ListenerService<P4RuntimeEvent, P4RuntimeEventListener> { |
| 29 | |
| 30 | /** |
Carmelo Cascone | 44448a5 | 2018-06-25 23:36:57 +0200 | [diff] [blame^] | 31 | * Instantiates a new client to operate on a P4Runtime device identified by |
| 32 | * the given information. As a result of this method, a {@link |
| 33 | * P4RuntimeClient} can be later obtained by invoking {@link |
| 34 | * #getClient(DeviceId)}. Returns true if the client was created and the |
| 35 | * channel to the device is open, false otherwise. |
| 36 | * <p> |
| 37 | * Only one client can exist for the same device ID. Calls to this method |
| 38 | * are idempotent for the same [device ID, address, port, p4DeviceId] tuple, |
| 39 | * i.e. returns true if such client already exists but a new one is not |
| 40 | * created. Throws an {@link IllegalStateException} if a client for device |
| 41 | * ID already exists but for different [address, port, p4DeviceId]. |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 42 | * |
Carmelo Cascone | 44448a5 | 2018-06-25 23:36:57 +0200 | [diff] [blame^] | 43 | * @param deviceId device identifier |
| 44 | * @param serverAddr address of the P4Runtime server |
| 45 | * @param serverPort port of the P4Runtime server |
| 46 | * @param p4DeviceId P4Runtime-specific device identifier |
| 47 | * @return true if the client was created and the channel to the device is |
| 48 | * open |
| 49 | * @throws IllegalStateException if a client already exists for this device |
| 50 | * ID but for different [address, port, |
| 51 | * p4DeviceId]. |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 52 | */ |
Carmelo Cascone | 44448a5 | 2018-06-25 23:36:57 +0200 | [diff] [blame^] | 53 | boolean createClient(DeviceId deviceId, String serverAddr, int serverPort, |
| 54 | long p4DeviceId); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Returns a client to operate on the given device. |
| 58 | * |
| 59 | * @param deviceId device identifier |
| 60 | * @return client instance |
| 61 | * @throws IllegalStateException if no client exists for the given device identifier |
| 62 | */ |
| 63 | P4RuntimeClient getClient(DeviceId deviceId); |
| 64 | |
| 65 | /** |
| 66 | * Removes the client for the given device. If no client exists for the given device identifier, the |
| 67 | * result is a no-op. |
| 68 | * |
| 69 | * @param deviceId device identifier |
| 70 | */ |
| 71 | void removeClient(DeviceId deviceId); |
| 72 | |
| 73 | /** |
| 74 | * Returns true if a client exists for the given device identifier, false otherwise. |
| 75 | * |
| 76 | * @param deviceId device identifier |
| 77 | * @return true if client exists, false otherwise. |
| 78 | */ |
| 79 | boolean hasClient(DeviceId deviceId); |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * Returns true if the P4Runtime server running on the given device is reachable, i.e. the channel is open and the |
| 83 | * server is able to respond to RPCs, false otherwise. Reachability can be tested only if a client was previously |
Carmelo Cascone | 44448a5 | 2018-06-25 23:36:57 +0200 | [diff] [blame^] | 84 | * created using {@link #createClient(DeviceId, String, int, long)}, otherwise this method returns false. |
Carmelo Cascone | 59f57de | 2017-07-11 19:55:09 -0400 | [diff] [blame] | 85 | * |
| 86 | * @param deviceId device identifier. |
| 87 | * @return true if a client was created and is able to contact the P4Runtime server, false otherwise. |
| 88 | */ |
| 89 | boolean isReacheable(DeviceId deviceId); |
Yi Tseng | 3e7f145 | 2017-10-20 10:31:53 -0700 | [diff] [blame] | 90 | |
| 91 | /** |
| 92 | * Gets new election id for device arbitration request. |
| 93 | * |
| 94 | * @return the election id |
| 95 | */ |
| 96 | long getNewMasterElectionId(); |
Andrea Campanella | 1e57344 | 2018-05-17 17:07:13 +0200 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * Adds a listener for P4Runtime client-server channel events. |
| 100 | * If the channel for the device is not present and/or established the listener will get notified |
| 101 | * only after channel setup. |
| 102 | * |
| 103 | * @param deviceId device identifier |
| 104 | * @param listener the channel listener |
| 105 | */ |
| 106 | void addChannelListener(DeviceId deviceId, ChannelListener listener); |
| 107 | |
| 108 | /** |
| 109 | * Removes the listener for P4Runtime client-server channel events. |
| 110 | * |
| 111 | * @param deviceId device identifier |
| 112 | * @param listener the channel listener |
| 113 | */ |
| 114 | void removeChannelListener(DeviceId deviceId, ChannelListener listener); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 115 | } |