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 | |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 19 | import com.google.common.annotations.Beta; |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 20 | import org.slf4j.Logger; |
| 21 | import org.slf4j.LoggerFactory; |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 22 | |
Yuta HIGUCHI | 5ac3443 | 2018-02-13 16:29:15 -0800 | [diff] [blame] | 23 | import static com.google.common.base.Preconditions.checkNotNull; |
| 24 | |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 25 | import java.util.Set; |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 26 | import java.util.concurrent.CompletableFuture; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * NETCONF session object that allows NETCONF operations on top with the physical |
| 30 | * device on top of an SSH connection. |
| 31 | */ |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 32 | // TODO change return type of methods to <Capability, XMLdoc, string or yang obj> |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 33 | public interface NetconfSession { |
| 34 | |
| 35 | /** |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 36 | * Executes an asynchronous RPC to the server and obtains a future to be completed. |
| 37 | * |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 38 | * The caller must ensure that the message-id in any request is unique |
| 39 | * for the session |
| 40 | * |
| 41 | * @deprecated - 1.10.0 do not remove needs reworking |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 42 | * @param request the XML containing the RPC for the server. |
| 43 | * @return Server response or ERROR |
| 44 | * @throws NetconfException when there is a problem in the communication process on |
| 45 | * the underlying connection |
| 46 | */ |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 47 | @Deprecated |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 48 | CompletableFuture<String> request(String request) throws NetconfException; |
| 49 | |
Yuta HIGUCHI | 6e6c26e | 2017-09-06 14:25:57 -0700 | [diff] [blame] | 50 | /** |
| 51 | * Executes an asynchronous RPC request to the server and obtains a future |
| 52 | * for it's response. |
| 53 | * |
| 54 | * @param request the XML containing the RPC request for the server. |
| 55 | * @return Server response or ERROR |
| 56 | * @throws NetconfException when there is a problem in the communication process on |
| 57 | * the underlying connection |
| 58 | * @throws NetconfTransportException on secure transport-layer error |
| 59 | */ |
| 60 | default CompletableFuture<String> rpc(String request) throws NetconfException { |
| 61 | return request(request); |
| 62 | } |
| 63 | |
Yuta HIGUCHI | 5ac3443 | 2018-02-13 16:29:15 -0800 | [diff] [blame] | 64 | /** |
| 65 | * Retrieves the specified configuration. |
| 66 | * |
| 67 | * @param datastore to retrieve configuration from |
| 68 | * @return specified configuration |
| 69 | * |
| 70 | * @throws NetconfException when there is a problem in the communication process on |
| 71 | * the underlying connection |
| 72 | */ |
| 73 | default CompletableFuture<CharSequence> asyncGetConfig(DatastoreId datastore) throws NetconfException { |
| 74 | StringBuilder rpc = new StringBuilder(); |
| 75 | rpc.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"); |
| 76 | rpc.append("<get-config>\n"); |
| 77 | rpc.append("<source>\n"); |
| 78 | rpc.append('<').append(checkNotNull(datastore)).append("/>"); |
| 79 | rpc.append("</source>"); |
| 80 | // filter here |
| 81 | rpc.append("</get-config>\n"); |
| 82 | rpc.append("</rpc>"); |
| 83 | |
| 84 | return rpc(rpc.toString()) |
| 85 | .thenApply(msg -> { |
| 86 | // crude way of removing rpc-reply envelope |
| 87 | int begin = msg.indexOf("<data>"); |
| 88 | int end = msg.lastIndexOf("</data>"); |
| 89 | if (begin != -1 && end != -1) { |
| 90 | return msg.subSequence(begin + "<data>".length(), end); |
| 91 | } else { |
| 92 | // FIXME probably should exceptionally fail here. |
| 93 | return msg; |
| 94 | } |
| 95 | }); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Retrieves running configuration and device state. |
| 100 | * |
| 101 | * @return running configuration and device state |
| 102 | * |
| 103 | * @throws NetconfException when there is a problem in the communication process on |
| 104 | * the underlying connection |
| 105 | */ |
| 106 | default CompletableFuture<CharSequence> asyncGet() throws NetconfException { |
| 107 | StringBuilder rpc = new StringBuilder(); |
| 108 | rpc.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"); |
| 109 | rpc.append("<get>\n"); |
| 110 | // filter here |
| 111 | rpc.append("</get>\n"); |
| 112 | rpc.append("</rpc>"); |
| 113 | return rpc(rpc.toString()) |
| 114 | .thenApply(msg -> { |
| 115 | // crude way of removing rpc-reply envelope |
| 116 | int begin = msg.indexOf("<data>"); |
| 117 | int end = msg.lastIndexOf("</data>"); |
| 118 | if (begin != -1 && end != -1) { |
| 119 | return msg.subSequence(begin + "<data>".length(), end); |
| 120 | } else { |
| 121 | // FIXME probably should exceptionally fail here. |
| 122 | return msg; |
| 123 | } |
| 124 | }); |
| 125 | |
| 126 | } |
| 127 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 128 | |
| 129 | /** |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 130 | * Retrieves the requested configuration, different from get-config. |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 131 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 132 | * @param request the XML containing the request to the server. |
| 133 | * @return device running configuration |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 134 | * @throws NetconfException when there is a problem in the communication process on |
| 135 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 136 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 137 | String get(String request) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 138 | |
| 139 | /** |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 140 | * Retrieves the requested data. |
Akihiro Yamanouchi | 5e5d4df | 2016-06-08 17:06:33 +0900 | [diff] [blame] | 141 | * |
| 142 | * @param filterSchema XML subtrees to include in the reply |
| 143 | * @param withDefaultsMode with-defaults mode |
| 144 | * @return Server response |
| 145 | * @throws NetconfException when there is a problem in the communication process on |
| 146 | * the underlying connection |
| 147 | */ |
| 148 | String get(String filterSchema, String withDefaultsMode) |
| 149 | throws NetconfException; |
| 150 | |
| 151 | /** |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 152 | * 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] | 153 | * |
| 154 | * @param request the XML containing the request to the server. |
| 155 | * @return Server response or ERROR |
| 156 | * @throws NetconfException when there is a problem in the communication process on |
| 157 | * the underlying connection |
| 158 | */ |
| 159 | String doWrappedRpc(String request) throws NetconfException; |
| 160 | |
| 161 | /** |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 162 | * Executes an synchronous RPC to the server. |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 163 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 164 | * @param request the XML containing the RPC for the server. |
| 165 | * @return Server response or ERROR |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 166 | * @throws NetconfException when there is a problem in the communication process on |
| 167 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 168 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 169 | String requestSync(String request) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 170 | |
| 171 | /** |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 172 | * Retrieves the specified configuration. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 173 | * |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 174 | * @param netconfTargetConfig the type of configuration to retrieve. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 175 | * @return specified configuration. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 176 | * @throws NetconfException when there is a problem in the communication process on |
| 177 | * the underlying connection |
Yuta HIGUCHI | 5ac3443 | 2018-02-13 16:29:15 -0800 | [diff] [blame] | 178 | * |
| 179 | * @deprecated in 1.13.0 use async version instead. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 180 | */ |
Yuta HIGUCHI | 5ac3443 | 2018-02-13 16:29:15 -0800 | [diff] [blame] | 181 | @Deprecated |
Yuta HIGUCHI | dd7c3f8 | 2017-09-03 14:18:01 -0700 | [diff] [blame] | 182 | String getConfig(DatastoreId netconfTargetConfig) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 183 | |
| 184 | /** |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 185 | * Retrieves part of the specified configuration based on the filterSchema. |
| 186 | * |
| 187 | * @param netconfTargetConfig the type of configuration to retrieve. |
| 188 | * @param configurationFilterSchema XML schema to filter the configuration |
| 189 | * elements we are interested in |
| 190 | * @return device running configuration. |
| 191 | * @throws NetconfException when there is a problem in the communication process on |
| 192 | * the underlying connection |
| 193 | */ |
Yuta HIGUCHI | dd7c3f8 | 2017-09-03 14:18:01 -0700 | [diff] [blame] | 194 | String getConfig(DatastoreId netconfTargetConfig, |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 195 | String configurationFilterSchema) |
Yuta HIGUCHI | dd7c3f8 | 2017-09-03 14:18:01 -0700 | [diff] [blame] | 196 | throws NetconfException; |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 197 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 198 | /** |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 199 | * Retrieves part of the specified configuration based on the filterSchema. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 200 | * |
| 201 | * @param newConfiguration configuration to set |
| 202 | * @return true if the configuration was edited correctly |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 203 | * @throws NetconfException when there is a problem in the communication process on |
| 204 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 205 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 206 | boolean editConfig(String newConfiguration) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 207 | |
| 208 | /** |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 209 | * Retrieves part of the specified configuration based on the filterSchema. |
| 210 | * |
| 211 | * @param netconfTargetConfig the targetConfiguration to change |
Yuta HIGUCHI | e34c9c2 | 2017-12-04 17:47:14 -0800 | [diff] [blame] | 212 | * @param mode default-operation mode |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 213 | * @param newConfiguration configuration to set |
| 214 | * @return true if the configuration was edited correctly |
| 215 | * @throws NetconfException when there is a problem in the communication process on |
| 216 | * the underlying connection |
| 217 | */ |
Yuta HIGUCHI | dd7c3f8 | 2017-09-03 14:18:01 -0700 | [diff] [blame] | 218 | boolean editConfig(DatastoreId netconfTargetConfig, String mode, String newConfiguration) |
| 219 | throws NetconfException; |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 220 | |
| 221 | /** |
| 222 | * Copies the configuration between configuration datastores. |
| 223 | * <p> |
| 224 | * The target configuration can't be the running one |
| 225 | * |
| 226 | * @param destination configuration datastore |
| 227 | * @param source configuration datastore |
| 228 | * @return true if the configuration was copied correctly |
| 229 | * @throws NetconfException when there is a problem in the communication process on |
| 230 | * the underlying connection |
| 231 | */ |
Yuta HIGUCHI | dd7c3f8 | 2017-09-03 14:18:01 -0700 | [diff] [blame] | 232 | boolean copyConfig(DatastoreId destination, DatastoreId source) |
| 233 | throws NetconfException; |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 234 | |
| 235 | /** |
| 236 | * Copies the new configuration, an Url or a complete configuration xml tree |
| 237 | * to the target configuration. |
| 238 | * The target configuration can't be the running one |
| 239 | * |
| 240 | * @param netconfTargetConfig the type of configuration to retrieve. |
| 241 | * @param newConfiguration configuration XML to set or URL tag to the configuration |
| 242 | * @return true if the configuration was copied correctly |
| 243 | * @throws NetconfException when there is a problem in the communication process on |
| 244 | * the underlying connection |
| 245 | */ |
Yuta HIGUCHI | dd7c3f8 | 2017-09-03 14:18:01 -0700 | [diff] [blame] | 246 | boolean copyConfig(DatastoreId netconfTargetConfig, String newConfiguration) |
| 247 | throws NetconfException; |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 248 | |
| 249 | /** |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 250 | * Copies the new configuration, an Url or a complete configuration xml tree |
| 251 | * to the target configuration. |
| 252 | * The target configuration can't be the running one |
| 253 | * |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 254 | * @param netconfTargetConfig the type of configuration to retrieve. |
| 255 | * @param newConfiguration configuration to set |
| 256 | * @return true if the configuration was copied correctly |
| 257 | * @throws NetconfException when there is a problem in the communication process on |
| 258 | * the underlying connection |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 259 | */ |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 260 | boolean copyConfig(String netconfTargetConfig, String newConfiguration) |
| 261 | throws NetconfException; |
| 262 | |
| 263 | /** |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 264 | * Deletes part of the specified configuration based on the filterSchema. |
| 265 | * |
| 266 | * @param netconfTargetConfig the name of the configuration to delete |
| 267 | * @return true if the configuration was copied correctly |
| 268 | * @throws NetconfException when there is a problem in the communication process on |
| 269 | * the underlying connection |
| 270 | */ |
Yuta HIGUCHI | dd7c3f8 | 2017-09-03 14:18:01 -0700 | [diff] [blame] | 271 | boolean deleteConfig(DatastoreId netconfTargetConfig) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 272 | |
| 273 | /** |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 274 | * Starts subscription to the device's notifications. |
| 275 | * |
| 276 | * @throws NetconfException when there is a problem starting the subscription |
| 277 | */ |
| 278 | void startSubscription() throws NetconfException; |
| 279 | |
| 280 | /** |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 281 | * Starts subscription to the device's notifications. |
| 282 | * |
| 283 | * @param filterSchema XML subtrees to indicate specific notification |
| 284 | * @throws NetconfException when there is a problem starting the subscription |
| 285 | */ |
| 286 | @Beta |
| 287 | void startSubscription(String filterSchema) throws NetconfException; |
| 288 | |
| 289 | /** |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 290 | * Ends subscription to the device's notifications. |
| 291 | * |
| 292 | * @throws NetconfException when there is a problem ending the subscription |
| 293 | */ |
| 294 | void endSubscription() throws NetconfException; |
| 295 | |
| 296 | /** |
| 297 | * Locks the specified configuration. |
| 298 | * |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 299 | * @param datastore configuration datastore to be locked |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 300 | * @return true if successful. |
| 301 | * @throws NetconfException when there is a problem in the communication process on |
| 302 | * the underlying connection |
| 303 | */ |
Yuta HIGUCHI | dd7c3f8 | 2017-09-03 14:18:01 -0700 | [diff] [blame] | 304 | boolean lock(DatastoreId datastore) throws NetconfException; |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 305 | |
| 306 | /** |
| 307 | * Unlocks the specified configuration. |
| 308 | * |
| 309 | * @param datastore configuration datastore to be unlocked |
| 310 | * @return true if successful. |
| 311 | * @throws NetconfException when there is a problem in the communication process on |
| 312 | * the underlying connection |
| 313 | */ |
Yuta HIGUCHI | dd7c3f8 | 2017-09-03 14:18:01 -0700 | [diff] [blame] | 314 | boolean unlock(DatastoreId datastore) throws NetconfException; |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 315 | |
| 316 | /** |
| 317 | * Locks the running configuration. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 318 | * |
| 319 | * @return true if successful. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 320 | * @throws NetconfException when there is a problem in the communication process on |
| 321 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 322 | */ |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 323 | default boolean lock() throws NetconfException { |
| 324 | return lock(DatastoreId.RUNNING); |
| 325 | } |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 326 | |
| 327 | /** |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 328 | * Unlocks the running configuration. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 329 | * |
| 330 | * @return true if successful. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 331 | * @throws NetconfException when there is a problem in the communication process on |
| 332 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 333 | */ |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 334 | default boolean unlock() throws NetconfException { |
| 335 | return unlock(DatastoreId.RUNNING); |
| 336 | } |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 337 | |
| 338 | /** |
| 339 | * Closes the Netconf session with the device. |
| 340 | * the first time it tries gracefully, then kills it forcefully |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 341 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 342 | * @return true if closed |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 343 | * @throws NetconfException when there is a problem in the communication process on |
| 344 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 345 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 346 | boolean close() throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 347 | |
| 348 | /** |
| 349 | * Gets the session ID of the Netconf session. |
| 350 | * |
| 351 | * @return Session ID as a string. |
| 352 | */ |
| 353 | String getSessionId(); |
| 354 | |
| 355 | /** |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 356 | * Gets the capabilities of the remote Netconf device associated to this |
| 357 | * session. |
| 358 | * |
| 359 | * @return Network capabilities as strings in a Set. |
| 360 | * |
| 361 | * @since 1.10.0 |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 362 | */ |
Yuta HIGUCHI | dd7c3f8 | 2017-09-03 14:18:01 -0700 | [diff] [blame] | 363 | Set<String> getDeviceCapabilitiesSet(); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 364 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 365 | /** |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 366 | * Checks the state of the underlying SSH session and connection |
| 367 | * and if necessary it reestablishes it. |
| 368 | * Should be implemented, providing a default here for retrocompatibility. |
| 369 | * @throws NetconfException when there is a problem in reestablishing |
| 370 | * the connection or the session to the device. |
| 371 | */ |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 372 | default void checkAndReestablish() throws NetconfException { |
| 373 | Logger log = LoggerFactory.getLogger(NetconfSession.class); |
| 374 | log.error("Not implemented/exposed by the underlying session implementation"); |
| 375 | } |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 376 | |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 377 | /** |
| 378 | * Sets the ONOS side capabilities. |
| 379 | * |
| 380 | * @param capabilities list of capabilities ONOS has. |
| 381 | * |
| 382 | * @since 1.10.0 |
| 383 | */ |
| 384 | default void setOnosCapabilities(Iterable<String> capabilities) { |
| 385 | // default implementation should be removed in the future |
| 386 | // no-op |
| 387 | } |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 388 | |
| 389 | /** |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 390 | * Remove a listener from the underlying stream handler implementation. |
| 391 | * |
| 392 | * @param listener event listener. |
| 393 | */ |
| 394 | void addDeviceOutputListener(NetconfDeviceOutputEventListener listener); |
| 395 | |
| 396 | /** |
| 397 | * Remove a listener from the underlying stream handler implementation. |
| 398 | * |
| 399 | * @param listener event listener. |
| 400 | */ |
| 401 | void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener); |
| 402 | |
Sean Condon | 54d8243 | 2017-07-26 22:27:25 +0100 | [diff] [blame] | 403 | /** |
| 404 | * Read the connect timeout that this session was created with. |
| 405 | * @return timeout in seconds |
| 406 | */ |
| 407 | default int timeoutConnectSec() { |
| 408 | return 0; |
| 409 | }; |
| 410 | |
| 411 | /** |
| 412 | * Read the reply timeout that this session was created with. |
| 413 | * @return timeout in seconds |
| 414 | */ |
| 415 | default int timeoutReplySec() { |
| 416 | return 0; |
| 417 | }; |
| 418 | |
| 419 | /** |
| 420 | * Read the idle timeout that this session was created with. |
| 421 | * @return timeout in seconds |
| 422 | */ |
| 423 | default int timeoutIdleSec() { |
| 424 | return 0; |
| 425 | }; |
| 426 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 427 | } |