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