blob: bceaeff5d277cf991946468d55d4f8461888e113 [file] [log] [blame]
Andrea Campanella241896c2017-05-10 13:11:04 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Andrea Campanella241896c2017-05-10 13:11:04 -07003 *
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
17package org.onosproject.net.device;
18
19import com.google.common.annotations.Beta;
20import org.onosproject.net.MastershipRole;
21import org.onosproject.net.driver.DeviceConnect;
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070022import org.onosproject.net.provider.ProviderId;
Andrea Campanella241896c2017-05-10 13:11:04 -070023
24import 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
31public interface DeviceHandshaker extends DeviceConnect {
32
33 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +020034 * 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 Campanella241896c2017-05-10 13:11:04 -070037 *
38 * @return CompletableFuture eventually true if reachable, false otherwise
39 */
40 CompletableFuture<Boolean> isReachable();
41
42 /**
Carmelo Casconee5b28722018-06-22 17:28:28 +020043 * 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 Campanella241896c2017-05-10 13:11:04 -070046 *
Carmelo Casconee5b28722018-06-22 17:28:28 +020047 * @param newRole new mastership role
Andrea Campanella241896c2017-05-10 13:11:04 -070048 */
Carmelo Casconee5b28722018-06-22 17:28:28 +020049 void roleChanged(MastershipRole newRole);
Andrea Campanella241896c2017-05-10 13:11:04 -070050
Andrea Campanella1e573442018-05-17 17:07:13 +020051 /**
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070052 * Returns the last known mastership role agreed by the device for this
53 * node.
Andrea Campanella1e573442018-05-17 17:07:13 +020054 *
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070055 * @return mastership role
Andrea Campanella1e573442018-05-17 17:07:13 +020056 */
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070057 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 Casconee5b28722018-06-22 17:28:28 +020067 throw new UnsupportedOperationException(
68 "Device agent listener registration not supported");
Andrea Campanella1e573442018-05-17 17:07:13 +020069 }
70
71 /**
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070072 * Removes a device agent listener previously registered for the given
73 * provider ID.
Andrea Campanella1e573442018-05-17 17:07:13 +020074 *
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070075 * @param providerId provider ID
Andrea Campanella1e573442018-05-17 17:07:13 +020076 */
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070077 default void removeDeviceAgentListener(ProviderId providerId) {
Carmelo Casconee5b28722018-06-22 17:28:28 +020078 throw new UnsupportedOperationException(
79 "Device agent listener removal not supported");
Andrea Campanella1e573442018-05-17 17:07:13 +020080 }
81
Andrea Campanella241896c2017-05-10 13:11:04 -070082}