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