andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
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 java.util.List; |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 20 | import java.util.concurrent.CompletableFuture; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * NETCONF session object that allows NETCONF operations on top with the physical |
| 24 | * device on top of an SSH connection. |
| 25 | */ |
| 26 | // TODO change return type of methdos to <Capability, XMLdoc, string or yang obj> |
| 27 | public interface NetconfSession { |
| 28 | |
| 29 | /** |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 30 | * Executes an asynchronous RPC to the server and obtains a future to be completed. |
| 31 | * |
| 32 | * @param request the XML containing the RPC for the server. |
| 33 | * @return Server response or ERROR |
| 34 | * @throws NetconfException when there is a problem in the communication process on |
| 35 | * the underlying connection |
| 36 | */ |
| 37 | CompletableFuture<String> request(String request) throws NetconfException; |
| 38 | |
| 39 | |
| 40 | /** |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 41 | * Retrives the requested configuration, different from get-config. |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 42 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 43 | * @param request the XML containing the request to the server. |
| 44 | * @return device running configuration |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 45 | * @throws NetconfException when there is a problem in the communication process on |
| 46 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 47 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 48 | String get(String request) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 49 | |
| 50 | /** |
Akihiro Yamanouchi | 5e5d4df | 2016-06-08 17:06:33 +0900 | [diff] [blame] | 51 | * Retrives the requested data. |
| 52 | * |
| 53 | * @param filterSchema XML subtrees to include in the reply |
| 54 | * @param withDefaultsMode with-defaults mode |
| 55 | * @return Server response |
| 56 | * @throws NetconfException when there is a problem in the communication process on |
| 57 | * the underlying connection |
| 58 | */ |
| 59 | String get(String filterSchema, String withDefaultsMode) |
| 60 | throws NetconfException; |
| 61 | |
| 62 | /** |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 63 | * Executes an synchronous RPC to the server. |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 64 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 65 | * @param request the XML containing the RPC for the server. |
| 66 | * @return Server response or ERROR |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 67 | * @throws NetconfException when there is a problem in the communication process on |
| 68 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 69 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 70 | String requestSync(String request) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 71 | |
| 72 | /** |
| 73 | * Retrives the specified configuration. |
| 74 | * |
| 75 | * @param targetConfiguration the type of configuration to retrieve. |
| 76 | * @return specified configuration. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 77 | * @throws NetconfException when there is a problem in the communication process on |
| 78 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 79 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 80 | String getConfig(String targetConfiguration) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * Retrives part of the specivied configuration based on the filterSchema. |
| 84 | * |
| 85 | * @param targetConfiguration the type of configuration to retrieve. |
| 86 | * @param configurationFilterSchema XML schema to filter the configuration |
| 87 | * elements we are interested in |
| 88 | * @return device running configuration. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 89 | * @throws NetconfException when there is a problem in the communication process on |
| 90 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 91 | */ |
Andrea Campanella | 1cd641b | 2015-12-07 17:28:34 -0800 | [diff] [blame] | 92 | String getConfig(String targetConfiguration, String configurationFilterSchema) |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 93 | throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 94 | |
| 95 | /** |
| 96 | * Retrives part of the specified configuration based on the filterSchema. |
| 97 | * |
| 98 | * @param newConfiguration configuration to set |
| 99 | * @return true if the configuration was edited correctly |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 100 | * @throws NetconfException when there is a problem in the communication process on |
| 101 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 102 | */ |
| 103 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 104 | boolean editConfig(String newConfiguration) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 105 | |
| 106 | /** |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 107 | * Retrives part of the specified configuration based on the filterSchema. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 108 | * |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 109 | * @param targetConfiguration the targetConfiguration to change |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 110 | * @param mode selected mode to change the configuration |
| 111 | * @param newConfiguration configuration to set |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 112 | * @return true if the configuration was edited correctly |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 113 | * @throws NetconfException when there is a problem in the communication process on |
| 114 | * the underlying connection |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 115 | */ |
| 116 | boolean editConfig(String targetConfiguration, String mode, String newConfiguration) |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 117 | throws NetconfException; |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 118 | |
| 119 | /** |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 120 | * Copies the new configuration, an Url or a complete configuration xml tree |
| 121 | * to the target configuration. |
| 122 | * The target configuration can't be the running one |
| 123 | * |
| 124 | * @param targetConfiguration the type of configuration to retrieve. |
| 125 | * @param newConfiguration configuration to set |
| 126 | * @return true if the configuration was copied correctly |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 127 | * @throws NetconfException when there is a problem in the communication process on |
| 128 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 129 | */ |
Andrea Campanella | 1cd641b | 2015-12-07 17:28:34 -0800 | [diff] [blame] | 130 | boolean copyConfig(String targetConfiguration, String newConfiguration) |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 131 | throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 132 | |
| 133 | /** |
| 134 | * Deletes part of the specified configuration based on the filterSchema. |
| 135 | * |
| 136 | * @param targetConfiguration the name of the configuration to delete |
| 137 | * @return true if the configuration was copied correctly |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 138 | * @throws NetconfException when there is a problem in the communication process on |
| 139 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 140 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 141 | boolean deleteConfig(String targetConfiguration) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 142 | |
| 143 | /** |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame^] | 144 | * Starts subscription to the device's notifications. |
| 145 | * |
| 146 | * @throws NetconfException when there is a problem starting the subscription |
| 147 | */ |
| 148 | void startSubscription() throws NetconfException; |
| 149 | |
| 150 | /** |
| 151 | * Ends subscription to the device's notifications. |
| 152 | * |
| 153 | * @throws NetconfException when there is a problem ending the subscription |
| 154 | */ |
| 155 | void endSubscription() throws NetconfException; |
| 156 | |
| 157 | /** |
| 158 | * Locks the specified configuration. |
| 159 | * |
| 160 | * @param configType type of configuration to be locked |
| 161 | * @return true if successful. |
| 162 | * @throws NetconfException when there is a problem in the communication process on |
| 163 | * the underlying connection |
| 164 | */ |
| 165 | boolean lock(String configType) throws NetconfException; |
| 166 | |
| 167 | /** |
| 168 | * Unlocks the specified configuration. |
| 169 | * |
| 170 | * @param configType type of configuration to be locked |
| 171 | * @return true if successful. |
| 172 | * @throws NetconfException when there is a problem in the communication process on |
| 173 | * the underlying connection |
| 174 | */ |
| 175 | boolean unlock(String configType) throws NetconfException; |
| 176 | |
| 177 | /** |
| 178 | * Locks the running configuration. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 179 | * |
| 180 | * @return true if successful. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 181 | * @throws NetconfException when there is a problem in the communication process on |
| 182 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 183 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 184 | boolean lock() throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 185 | |
| 186 | /** |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame^] | 187 | * Unlocks the running configuration. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 188 | * |
| 189 | * @return true if successful. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 190 | * @throws NetconfException when there is a problem in the communication process on |
| 191 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 192 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 193 | boolean unlock() throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 194 | |
| 195 | /** |
| 196 | * Closes the Netconf session with the device. |
| 197 | * the first time it tries gracefully, then kills it forcefully |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 198 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 199 | * @return true if closed |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 200 | * @throws NetconfException when there is a problem in the communication process on |
| 201 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 202 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 203 | boolean close() throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 204 | |
| 205 | /** |
| 206 | * Gets the session ID of the Netconf session. |
| 207 | * |
| 208 | * @return Session ID as a string. |
| 209 | */ |
| 210 | String getSessionId(); |
| 211 | |
| 212 | /** |
| 213 | * Gets the capabilities of the Netconf server associated to this session. |
| 214 | * |
| 215 | * @return Network capabilities as a string. |
| 216 | */ |
| 217 | String getServerCapabilities(); |
| 218 | |
| 219 | /** |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 220 | * Sets the ONOS side capabilities. |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 221 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 222 | * @param capabilities list of capabilities the device has. |
| 223 | */ |
| 224 | void setDeviceCapabilities(List<String> capabilities); |
| 225 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 226 | /** |
| 227 | * Remove a listener from the underlying stream handler implementation. |
| 228 | * |
| 229 | * @param listener event listener. |
| 230 | */ |
| 231 | void addDeviceOutputListener(NetconfDeviceOutputEventListener listener); |
| 232 | |
| 233 | /** |
| 234 | * Remove a listener from the underlying stream handler implementation. |
| 235 | * |
| 236 | * @param listener event listener. |
| 237 | */ |
| 238 | void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener); |
| 239 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 240 | } |