andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
andrea | eb70a94 | 2015-10-16 21:34:46 -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.netconf; |
| 18 | |
| 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onosproject.net.DeviceId; |
| 21 | |
| 22 | import java.util.Map; |
Andrea Campanella | 86294db | 2016-03-07 11:42:49 -0800 | [diff] [blame] | 23 | import java.util.Set; |
gyewan.an | 91d7e7e | 2019-01-17 15:12:48 +0900 | [diff] [blame^] | 24 | import java.util.concurrent.CompletableFuture; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Abstraction of an NETCONF controller. Serves as a one stop shop for obtaining |
| 28 | * NetconfDevice and (un)register listeners on NETCONF device events. |
| 29 | */ |
| 30 | public interface NetconfController { |
| 31 | |
| 32 | /** |
| 33 | * Adds Device Event Listener. |
| 34 | * |
| 35 | * @param listener node listener |
| 36 | */ |
| 37 | void addDeviceListener(NetconfDeviceListener listener); |
| 38 | |
| 39 | /** |
| 40 | * Removes Device Listener. |
| 41 | * |
| 42 | * @param listener node listener |
| 43 | */ |
| 44 | void removeDeviceListener(NetconfDeviceListener listener); |
| 45 | |
| 46 | /** |
| 47 | * Tries to connect to a specific NETCONF device, if the connection is succesful |
| 48 | * it creates and adds the device to the ONOS core as a NetconfDevice. |
| 49 | * |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 50 | * @param deviceId deviceId of the device to connect |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 51 | * @return NetconfDevice Netconf device |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 52 | * @throws NetconfException when device is not available |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 53 | */ |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 54 | NetconfDevice connectDevice(DeviceId deviceId) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
gyewan.an | 91d7e7e | 2019-01-17 15:12:48 +0900 | [diff] [blame^] | 57 | * Tries to connect to a specific NETCONF device, if the connection is succesful |
| 58 | * it creates and adds the device to the ONOS core as a NetconfDevice. |
| 59 | * If isMaster true: Will create two sessions for a device : secure transport session and proxy session. |
| 60 | * If isMaster false: Will create only proxy session. |
| 61 | * @param deviceId deviceId of the device to connect |
| 62 | * @param isMaster if the controller is master for the device |
| 63 | * @return NetconfDevice Netconf device |
| 64 | * @throws NetconfException when device is not available |
| 65 | */ |
| 66 | default NetconfDevice connectDevice(DeviceId deviceId, boolean isMaster) throws NetconfException { |
| 67 | return connectDevice(deviceId); |
| 68 | } |
| 69 | |
| 70 | /** |
Andrea Campanella | 86294db | 2016-03-07 11:42:49 -0800 | [diff] [blame] | 71 | * Disconnects a Netconf device and removes it from the core. |
| 72 | * |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 73 | * @param deviceId id of the device to remove |
| 74 | * @param remove true if device is to be removed from core |
Andrea Campanella | 86294db | 2016-03-07 11:42:49 -0800 | [diff] [blame] | 75 | */ |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 76 | void disconnectDevice(DeviceId deviceId, boolean remove); |
Andrea Campanella | 86294db | 2016-03-07 11:42:49 -0800 | [diff] [blame] | 77 | |
| 78 | /** |
| 79 | * Removes a Netconf device from the core. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 80 | * |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 81 | * @param deviceId id of the device to remove |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 82 | */ |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 83 | void removeDevice(DeviceId deviceId); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * Gets all the nodes information. |
| 87 | * |
| 88 | * @return map of devices |
| 89 | */ |
| 90 | Map<DeviceId, NetconfDevice> getDevicesMap(); |
| 91 | |
| 92 | /** |
Andrea Campanella | 86294db | 2016-03-07 11:42:49 -0800 | [diff] [blame] | 93 | * Gets all Netconf Devices. |
| 94 | * |
| 95 | * @return List of all the NetconfDevices Ids |
| 96 | */ |
| 97 | Set<DeviceId> getNetconfDevices(); |
| 98 | |
| 99 | /** |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 100 | * Gets a Netconf Device by node identifier. |
| 101 | * |
| 102 | * @param deviceInfo node identifier |
| 103 | * @return NetconfDevice Netconf device |
| 104 | */ |
| 105 | NetconfDevice getNetconfDevice(DeviceId deviceInfo); |
| 106 | |
| 107 | /** |
| 108 | * Gets a Netconf Device by node identifier. |
| 109 | * |
| 110 | * @param ip device ip |
| 111 | * @param port device port |
| 112 | * @return NetconfDevice Netconf device |
| 113 | */ |
| 114 | NetconfDevice getNetconfDevice(IpAddress ip, int port); |
David K. Bainbridge | 56e9023 | 2018-12-18 23:25:08 -0800 | [diff] [blame] | 115 | |
| 116 | /** |
| 117 | * Gets a Netconf Device by node identifier. |
| 118 | * |
| 119 | * @param ip device ip |
| 120 | * @param port device port |
| 121 | * @param path device path |
| 122 | * @return NetconfDevice Netconf device |
| 123 | */ |
| 124 | NetconfDevice getNetconfDevice(IpAddress ip, int port, String path); |
gyewan.an | 91d7e7e | 2019-01-17 15:12:48 +0900 | [diff] [blame^] | 125 | |
| 126 | /** |
| 127 | * If master, will execute the call locally else will use |
| 128 | * clusterCommunicationManager to execute at master controller. |
| 129 | * Meant only for internal synchronization and not to be used by applications. |
| 130 | * |
| 131 | * @param proxyMessage proxy message |
| 132 | * @param <T> return type |
| 133 | * @return Completable future of class T |
| 134 | * @throws NetconfException netconf exception |
| 135 | */ |
| 136 | default <T> CompletableFuture<T> executeAtMaster(NetconfProxyMessage proxyMessage) throws NetconfException { |
| 137 | CompletableFuture<T> errorFuture = new CompletableFuture<>(); |
| 138 | errorFuture.completeExceptionally(new NetconfException("Method executeAtMaster not implemented")); |
| 139 | return errorFuture; |
| 140 | } |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 141 | } |