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 | |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 19 | import com.google.common.annotations.Beta; |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame^] | 20 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 21 | import java.util.List; |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 22 | import java.util.concurrent.CompletableFuture; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * NETCONF session object that allows NETCONF operations on top with the physical |
| 26 | * device on top of an SSH connection. |
| 27 | */ |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 28 | // TODO change return type of methods to <Capability, XMLdoc, string or yang obj> |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 29 | public interface NetconfSession { |
| 30 | |
| 31 | /** |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 32 | * Executes an asynchronous RPC to the server and obtains a future to be completed. |
| 33 | * |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 34 | * The caller must ensure that the message-id in any request is unique |
| 35 | * for the session |
| 36 | * |
| 37 | * @deprecated - 1.10.0 do not remove needs reworking |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 38 | * @param request the XML containing the RPC for the server. |
| 39 | * @return Server response or ERROR |
| 40 | * @throws NetconfException when there is a problem in the communication process on |
| 41 | * the underlying connection |
| 42 | */ |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 43 | @Deprecated |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 44 | CompletableFuture<String> request(String request) throws NetconfException; |
| 45 | |
| 46 | |
| 47 | /** |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 48 | * Retrieves the requested configuration, different from get-config. |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 49 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 50 | * @param request the XML containing the request to the server. |
| 51 | * @return device running configuration |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 52 | * @throws NetconfException when there is a problem in the communication process on |
| 53 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 54 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 55 | String get(String request) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 56 | |
| 57 | /** |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 58 | * Retrieves the requested data. |
Akihiro Yamanouchi | 5e5d4df | 2016-06-08 17:06:33 +0900 | [diff] [blame] | 59 | * |
| 60 | * @param filterSchema XML subtrees to include in the reply |
| 61 | * @param withDefaultsMode with-defaults mode |
| 62 | * @return Server response |
| 63 | * @throws NetconfException when there is a problem in the communication process on |
| 64 | * the underlying connection |
| 65 | */ |
| 66 | String get(String filterSchema, String withDefaultsMode) |
| 67 | throws NetconfException; |
| 68 | |
| 69 | /** |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 70 | * Executes an synchronous RPC to the server and wrap the request in RPC header. |
Akihiro Yamanouchi | 8d3a9d3 | 2016-07-12 11:41:44 +0900 | [diff] [blame] | 71 | * |
| 72 | * @param request the XML containing the request to the server. |
| 73 | * @return Server response or ERROR |
| 74 | * @throws NetconfException when there is a problem in the communication process on |
| 75 | * the underlying connection |
| 76 | */ |
| 77 | String doWrappedRpc(String request) throws NetconfException; |
| 78 | |
| 79 | /** |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 80 | * Executes an synchronous RPC to the server. |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 81 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 82 | * @param request the XML containing the RPC for the server. |
| 83 | * @return Server response or ERROR |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 84 | * @throws NetconfException when there is a problem in the communication process on |
| 85 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 86 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 87 | String requestSync(String request) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * Retrives the specified configuration. |
| 91 | * |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame^] | 92 | * @param netconfTargetConfig the type of configuration to retrieve. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 93 | * @return specified configuration. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 94 | * @throws NetconfException when there is a problem in the communication process on |
| 95 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 96 | */ |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame^] | 97 | String getConfig(TargetConfig netconfTargetConfig) throws NetconfException; |
| 98 | |
| 99 | /** |
| 100 | * Retrives the specified configuration. |
| 101 | * |
| 102 | * @param netconfTargetConfig the type of configuration to retrieve. |
| 103 | * @return specified configuration. |
| 104 | * @throws NetconfException when there is a problem in the communication process on |
| 105 | * the underlying connection |
| 106 | * @deprecated - 1.10.0 Kingfisher use method overload that accepts |
| 107 | * org.onosproject.netconf.TargetConfig enum parameter instead |
| 108 | */ |
| 109 | @Deprecated |
| 110 | String getConfig(String netconfTargetConfig) throws NetconfException; |
| 111 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 112 | |
| 113 | /** |
| 114 | * Retrives part of the specivied configuration based on the filterSchema. |
| 115 | * |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame^] | 116 | * @param netconfTargetConfig the type of configuration to retrieve. |
| 117 | * @param configurationFilterSchema XML schema to filter the configuration |
| 118 | * elements we are interested in |
| 119 | * @return device running configuration. |
| 120 | * @throws NetconfException when there is a problem in the communication process on |
| 121 | * the underlying connection |
| 122 | * @deprecated - 1.10.0 Kingfisher use method overload that accepts |
| 123 | * org.onosproject.netconf.TargetConfig enum parameter instead |
| 124 | */ |
| 125 | @Deprecated |
| 126 | String getConfig(String netconfTargetConfig, String configurationFilterSchema) |
| 127 | throws NetconfException; |
| 128 | |
| 129 | /** |
| 130 | * Retrives part of the specivied configuration based on the filterSchema. |
| 131 | * |
| 132 | * @param netconfTargetConfig the type of configuration to retrieve. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 133 | * @param configurationFilterSchema XML schema to filter the configuration |
| 134 | * elements we are interested in |
| 135 | * @return device running configuration. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 136 | * @throws NetconfException when there is a problem in the communication process on |
| 137 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 138 | */ |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame^] | 139 | String getConfig(TargetConfig netconfTargetConfig, String configurationFilterSchema) |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 140 | throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 141 | |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame^] | 142 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 143 | /** |
| 144 | * Retrives part of the specified configuration based on the filterSchema. |
| 145 | * |
| 146 | * @param newConfiguration configuration to set |
| 147 | * @return true if the configuration was edited correctly |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 148 | * @throws NetconfException when there is a problem in the communication process on |
| 149 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 150 | */ |
| 151 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 152 | boolean editConfig(String newConfiguration) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 153 | |
| 154 | /** |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 155 | * Retrives part of the specified configuration based on the filterSchema. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 156 | * |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame^] | 157 | * @param netconfTargetConfig the targetConfiguration to change |
| 158 | * @param mode selected mode to change the configuration |
| 159 | * @param newConfiguration configuration to set |
| 160 | * @return true if the configuration was edited correctly |
| 161 | * @throws NetconfException when there is a problem in the communication process on |
| 162 | * the underlying connection |
| 163 | * @deprecated - 1.10.0 Kingfisher use method overload that accepts |
| 164 | * org.onosproject.netconf.TargetConfig enum parameter instead |
| 165 | */ |
| 166 | @Deprecated |
| 167 | boolean editConfig(String netconfTargetConfig, String mode, String newConfiguration) |
| 168 | throws NetconfException; |
| 169 | |
| 170 | /** |
| 171 | * Retrives part of the specified configuration based on the filterSchema. |
| 172 | * |
| 173 | * @param netconfTargetConfig the targetConfiguration to change |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 174 | * @param mode selected mode to change the configuration |
| 175 | * @param newConfiguration configuration to set |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 176 | * @return true if the configuration was edited correctly |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 177 | * @throws NetconfException when there is a problem in the communication process on |
| 178 | * the underlying connection |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 179 | */ |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame^] | 180 | boolean editConfig(TargetConfig netconfTargetConfig, String mode, String newConfiguration) |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 181 | throws NetconfException; |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 182 | |
| 183 | /** |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 184 | * Copies the new configuration, an Url or a complete configuration xml tree |
| 185 | * to the target configuration. |
| 186 | * The target configuration can't be the running one |
| 187 | * |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame^] | 188 | * @param netconfTargetConfig the type of configuration to retrieve. |
| 189 | * @param newConfiguration configuration to set |
| 190 | * @return true if the configuration was copied correctly |
| 191 | * @throws NetconfException when there is a problem in the communication process on |
| 192 | * the underlying connection |
| 193 | * @deprecated - 1.10.0 Kingfisher use method overload that accepts |
| 194 | * org.onosproject.netconf.TargetConfig enum parameter instead |
| 195 | */ |
| 196 | @Deprecated |
| 197 | boolean copyConfig(String netconfTargetConfig, String newConfiguration) |
| 198 | throws NetconfException; |
| 199 | |
| 200 | /** |
| 201 | * Copies the new configuration, an Url or a complete configuration xml tree |
| 202 | * to the target configuration. |
| 203 | * The target configuration can't be the running one |
| 204 | * |
| 205 | * @param netconfTargetConfig the type of configuration to retrieve. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 206 | * @param newConfiguration configuration to set |
| 207 | * @return true if the configuration was copied correctly |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 208 | * @throws NetconfException when there is a problem in the communication process on |
| 209 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 210 | */ |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame^] | 211 | boolean copyConfig(TargetConfig netconfTargetConfig, String newConfiguration) |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 212 | throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 213 | |
| 214 | /** |
| 215 | * Deletes part of the specified configuration based on the filterSchema. |
| 216 | * |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame^] | 217 | * @param netconfTargetConfig the name of the configuration to delete |
| 218 | * @return true if the configuration was copied correctly |
| 219 | * @throws NetconfException when there is a problem in the communication process on |
| 220 | * the underlying connection |
| 221 | * @deprecated - 1.10.0 Kingfisher use method overload that accepts |
| 222 | * org.onosproject.netconf.TargetConfig enum parameter instead |
| 223 | */ |
| 224 | @Deprecated |
| 225 | boolean deleteConfig(String netconfTargetConfig) throws NetconfException; |
| 226 | |
| 227 | /** |
| 228 | * Deletes part of the specified configuration based on the filterSchema. |
| 229 | * |
| 230 | * @param netconfTargetConfig the name of the configuration to delete |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 231 | * @return true if the configuration was copied correctly |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 232 | * @throws NetconfException when there is a problem in the communication process on |
| 233 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 234 | */ |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame^] | 235 | boolean deleteConfig(TargetConfig netconfTargetConfig) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 236 | |
| 237 | /** |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 238 | * Starts subscription to the device's notifications. |
| 239 | * |
| 240 | * @throws NetconfException when there is a problem starting the subscription |
| 241 | */ |
| 242 | void startSubscription() throws NetconfException; |
| 243 | |
| 244 | /** |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 245 | * Starts subscription to the device's notifications. |
| 246 | * |
| 247 | * @param filterSchema XML subtrees to indicate specific notification |
| 248 | * @throws NetconfException when there is a problem starting the subscription |
| 249 | */ |
| 250 | @Beta |
| 251 | void startSubscription(String filterSchema) throws NetconfException; |
| 252 | |
| 253 | /** |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 254 | * Ends subscription to the device's notifications. |
| 255 | * |
| 256 | * @throws NetconfException when there is a problem ending the subscription |
| 257 | */ |
| 258 | void endSubscription() throws NetconfException; |
| 259 | |
| 260 | /** |
| 261 | * Locks the specified configuration. |
| 262 | * |
| 263 | * @param configType type of configuration to be locked |
| 264 | * @return true if successful. |
| 265 | * @throws NetconfException when there is a problem in the communication process on |
| 266 | * the underlying connection |
| 267 | */ |
| 268 | boolean lock(String configType) throws NetconfException; |
| 269 | |
| 270 | /** |
| 271 | * Unlocks the specified configuration. |
| 272 | * |
| 273 | * @param configType type of configuration to be locked |
| 274 | * @return true if successful. |
| 275 | * @throws NetconfException when there is a problem in the communication process on |
| 276 | * the underlying connection |
| 277 | */ |
| 278 | boolean unlock(String configType) throws NetconfException; |
| 279 | |
| 280 | /** |
| 281 | * Locks the running configuration. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 282 | * |
| 283 | * @return true if successful. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 284 | * @throws NetconfException when there is a problem in the communication process on |
| 285 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 286 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 287 | boolean lock() throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 288 | |
| 289 | /** |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 290 | * Unlocks the running configuration. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 291 | * |
| 292 | * @return true if successful. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 293 | * @throws NetconfException when there is a problem in the communication process on |
| 294 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 295 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 296 | boolean unlock() throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 297 | |
| 298 | /** |
| 299 | * Closes the Netconf session with the device. |
| 300 | * the first time it tries gracefully, then kills it forcefully |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 301 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 302 | * @return true if closed |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 303 | * @throws NetconfException when there is a problem in the communication process on |
| 304 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 305 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 306 | boolean close() throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 307 | |
| 308 | /** |
| 309 | * Gets the session ID of the Netconf session. |
| 310 | * |
| 311 | * @return Session ID as a string. |
| 312 | */ |
| 313 | String getSessionId(); |
| 314 | |
| 315 | /** |
| 316 | * Gets the capabilities of the Netconf server associated to this session. |
| 317 | * |
| 318 | * @return Network capabilities as a string. |
| 319 | */ |
| 320 | String getServerCapabilities(); |
| 321 | |
| 322 | /** |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 323 | * Sets the ONOS side capabilities. |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 324 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 325 | * @param capabilities list of capabilities the device has. |
| 326 | */ |
| 327 | void setDeviceCapabilities(List<String> capabilities); |
| 328 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 329 | /** |
| 330 | * Remove a listener from the underlying stream handler implementation. |
| 331 | * |
| 332 | * @param listener event listener. |
| 333 | */ |
| 334 | void addDeviceOutputListener(NetconfDeviceOutputEventListener listener); |
| 335 | |
| 336 | /** |
| 337 | * Remove a listener from the underlying stream handler implementation. |
| 338 | * |
| 339 | * @param listener event listener. |
| 340 | */ |
| 341 | void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener); |
| 342 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 343 | } |