Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [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.net.device; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
| 20 | import org.onosproject.net.MastershipRole; |
| 21 | import org.onosproject.net.driver.DeviceConnect; |
Carmelo Cascone | 6c14804 | 2018-08-30 00:29:16 -0700 | [diff] [blame] | 22 | import org.onosproject.net.provider.ProviderId; |
Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 23 | |
| 24 | import java.util.concurrent.CompletableFuture; |
| 25 | |
| 26 | /** |
| 27 | * Behavior to test device's reachability and change the mastership role on that |
| 28 | * device. |
| 29 | */ |
| 30 | @Beta |
| 31 | public interface DeviceHandshaker extends DeviceConnect { |
| 32 | |
| 33 | /** |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 34 | * Checks the reachability (connectivity) of a device. Reachability, unlike |
| 35 | * availability, denotes whether THIS particular node can send messages and |
| 36 | * receive replies from the specified device. |
Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 37 | * |
| 38 | * @return CompletableFuture eventually true if reachable, false otherwise |
| 39 | */ |
| 40 | CompletableFuture<Boolean> isReachable(); |
| 41 | |
| 42 | /** |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 43 | * Notifies the device a mastership role change as decided by the core. The |
| 44 | * implementation of this method should trigger a {@link DeviceAgentEvent} |
| 45 | * signaling the mastership role accepted by the device. |
Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 46 | * |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 47 | * @param newRole new mastership role |
Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 48 | */ |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 49 | void roleChanged(MastershipRole newRole); |
Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 50 | |
Andrea Campanella | 1e57344 | 2018-05-17 17:07:13 +0200 | [diff] [blame] | 51 | /** |
Carmelo Cascone | 6c14804 | 2018-08-30 00:29:16 -0700 | [diff] [blame] | 52 | * Returns the last known mastership role agreed by the device for this |
| 53 | * node. |
Andrea Campanella | 1e57344 | 2018-05-17 17:07:13 +0200 | [diff] [blame] | 54 | * |
Carmelo Cascone | 6c14804 | 2018-08-30 00:29:16 -0700 | [diff] [blame] | 55 | * @return mastership role |
Andrea Campanella | 1e57344 | 2018-05-17 17:07:13 +0200 | [diff] [blame] | 56 | */ |
Carmelo Cascone | 6c14804 | 2018-08-30 00:29:16 -0700 | [diff] [blame] | 57 | MastershipRole getRole(); |
| 58 | |
| 59 | /** |
| 60 | * Adds a device agent listener for the given provider ID. |
| 61 | * |
| 62 | * @param providerId provider ID |
| 63 | * @param listener device agent listener |
| 64 | */ |
| 65 | default void addDeviceAgentListener( |
| 66 | ProviderId providerId, DeviceAgentListener listener) { |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 67 | throw new UnsupportedOperationException( |
| 68 | "Device agent listener registration not supported"); |
Andrea Campanella | 1e57344 | 2018-05-17 17:07:13 +0200 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /** |
Carmelo Cascone | 6c14804 | 2018-08-30 00:29:16 -0700 | [diff] [blame] | 72 | * Removes a device agent listener previously registered for the given |
| 73 | * provider ID. |
Andrea Campanella | 1e57344 | 2018-05-17 17:07:13 +0200 | [diff] [blame] | 74 | * |
Carmelo Cascone | 6c14804 | 2018-08-30 00:29:16 -0700 | [diff] [blame] | 75 | * @param providerId provider ID |
Andrea Campanella | 1e57344 | 2018-05-17 17:07:13 +0200 | [diff] [blame] | 76 | */ |
Carmelo Cascone | 6c14804 | 2018-08-30 00:29:16 -0700 | [diff] [blame] | 77 | default void removeDeviceAgentListener(ProviderId providerId) { |
Carmelo Cascone | e5b2872 | 2018-06-22 17:28:28 +0200 | [diff] [blame] | 78 | throw new UnsupportedOperationException( |
| 79 | "Device agent listener removal not supported"); |
Andrea Campanella | 1e57344 | 2018-05-17 17:07:13 +0200 | [diff] [blame] | 80 | } |
| 81 | |
Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 82 | } |