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 | |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 23 | import java.util.LinkedHashSet; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 24 | import java.util.List; |
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; |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 27 | import java.util.regex.Matcher; |
| 28 | import java.util.regex.Pattern; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * NETCONF session object that allows NETCONF operations on top with the physical |
| 32 | * device on top of an SSH connection. |
| 33 | */ |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 34 | // TODO change return type of methods to <Capability, XMLdoc, string or yang obj> |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 35 | public interface NetconfSession { |
| 36 | |
| 37 | /** |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 38 | * Executes an asynchronous RPC to the server and obtains a future to be completed. |
| 39 | * |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 40 | * The caller must ensure that the message-id in any request is unique |
| 41 | * for the session |
| 42 | * |
| 43 | * @deprecated - 1.10.0 do not remove needs reworking |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 44 | * @param request the XML containing the RPC for the server. |
| 45 | * @return Server response or ERROR |
| 46 | * @throws NetconfException when there is a problem in the communication process on |
| 47 | * the underlying connection |
| 48 | */ |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 49 | @Deprecated |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 50 | CompletableFuture<String> request(String request) throws NetconfException; |
| 51 | |
| 52 | |
| 53 | /** |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 54 | * Retrieves the requested configuration, different from get-config. |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 55 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 56 | * @param request the XML containing the request to the server. |
| 57 | * @return device running configuration |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 58 | * @throws NetconfException when there is a problem in the communication process on |
| 59 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 60 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 61 | String get(String request) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 62 | |
| 63 | /** |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 64 | * Retrieves the requested data. |
Akihiro Yamanouchi | 5e5d4df | 2016-06-08 17:06:33 +0900 | [diff] [blame] | 65 | * |
| 66 | * @param filterSchema XML subtrees to include in the reply |
| 67 | * @param withDefaultsMode with-defaults mode |
| 68 | * @return Server response |
| 69 | * @throws NetconfException when there is a problem in the communication process on |
| 70 | * the underlying connection |
| 71 | */ |
| 72 | String get(String filterSchema, String withDefaultsMode) |
| 73 | throws NetconfException; |
| 74 | |
| 75 | /** |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 76 | * 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] | 77 | * |
| 78 | * @param request the XML containing the request to the server. |
| 79 | * @return Server response or ERROR |
| 80 | * @throws NetconfException when there is a problem in the communication process on |
| 81 | * the underlying connection |
| 82 | */ |
| 83 | String doWrappedRpc(String request) throws NetconfException; |
| 84 | |
| 85 | /** |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 86 | * Executes an synchronous RPC to the server. |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 87 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 88 | * @param request the XML containing the RPC for the server. |
| 89 | * @return Server response or ERROR |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 90 | * @throws NetconfException when there is a problem in the communication process on |
| 91 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 92 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 93 | String requestSync(String request) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 94 | |
| 95 | /** |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 96 | * Retrieves the specified configuration. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 97 | * |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 98 | * @param netconfTargetConfig the type of configuration to retrieve. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 99 | * @return specified configuration. |
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 | */ |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 103 | default String getConfig(DatastoreId netconfTargetConfig) throws NetconfException { |
| 104 | // default implementation provided for backward compatibility |
| 105 | // this API is the one, which should be implemented |
| 106 | // TODO default implementation here should be removed after |
| 107 | // deprecation of the other 2 variants. |
| 108 | return getConfig(netconfTargetConfig.id()); |
| 109 | } |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 110 | |
| 111 | /** |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 112 | * Retrieves the specified configuration. |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 113 | * |
| 114 | * @param netconfTargetConfig the type of configuration to retrieve. |
| 115 | * @return specified configuration. |
| 116 | * @throws NetconfException when there is a problem in the communication process on |
| 117 | * the underlying connection |
| 118 | * @deprecated - 1.10.0 Kingfisher use method overload that accepts |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 119 | * org.onosproject.netconf.TargetConfiguration parameter instead |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 120 | */ |
| 121 | @Deprecated |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 122 | default String getConfig(TargetConfig netconfTargetConfig) throws NetconfException { |
| 123 | return getConfig(TargetConfig.toDatastoreId(netconfTargetConfig)); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Retrieves the specified configuration. |
| 128 | * |
| 129 | * @param netconfTargetConfig the type of configuration to retrieve. |
| 130 | * @return specified configuration. |
| 131 | * @throws NetconfException when there is a problem in the communication process on |
| 132 | * the underlying connection |
| 133 | * @deprecated - 1.10.0 Kingfisher use method overload that accepts |
| 134 | * org.onosproject.netconf.TargetConfiguration parameter instead |
| 135 | */ |
| 136 | @Deprecated |
| 137 | default String getConfig(String netconfTargetConfig) throws NetconfException { |
| 138 | return getConfig(TargetConfig.toDatastoreId(netconfTargetConfig)); |
| 139 | } |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 140 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 141 | |
| 142 | /** |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 143 | * Retrieves part of the specified configuration based on the filterSchema. |
| 144 | * |
| 145 | * @param netconfTargetConfig the type of configuration to retrieve. |
| 146 | * @param configurationFilterSchema XML schema to filter the configuration |
| 147 | * elements we are interested in |
| 148 | * @return device running configuration. |
| 149 | * @throws NetconfException when there is a problem in the communication process on |
| 150 | * the underlying connection |
| 151 | */ |
| 152 | default String getConfig(DatastoreId netconfTargetConfig, |
| 153 | String configurationFilterSchema) |
| 154 | throws NetconfException { |
| 155 | // default implementation provided for backward compatibility |
| 156 | // this API is the one, which should be implemented |
| 157 | // TODO default implementation here should be removed after |
| 158 | // deprecation of the other 2 variants. |
| 159 | return getConfig(netconfTargetConfig.id(), configurationFilterSchema); |
| 160 | } |
| 161 | |
| 162 | |
| 163 | /** |
| 164 | * Retrieves part of the specified configuration based on the filterSchema. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 165 | * |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 166 | * @param netconfTargetConfig the type of configuration to retrieve. |
| 167 | * @param configurationFilterSchema XML schema to filter the configuration |
| 168 | * elements we are interested in |
| 169 | * @return device running configuration. |
| 170 | * @throws NetconfException when there is a problem in the communication process on |
| 171 | * the underlying connection |
| 172 | * @deprecated - 1.10.0 Kingfisher use method overload that accepts |
| 173 | * org.onosproject.netconf.TargetConfig enum parameter instead |
| 174 | */ |
| 175 | @Deprecated |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 176 | default String getConfig(String netconfTargetConfig, String configurationFilterSchema) |
| 177 | throws NetconfException { |
| 178 | return getConfig(TargetConfig.toDatastoreId(netconfTargetConfig), |
| 179 | configurationFilterSchema); |
| 180 | } |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 181 | |
| 182 | /** |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 183 | * Retrieves part of the specified configuration based on the filterSchema. |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 184 | * |
| 185 | * @param netconfTargetConfig the type of configuration to retrieve. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 186 | * @param configurationFilterSchema XML schema to filter the configuration |
| 187 | * elements we are interested in |
| 188 | * @return device running configuration. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 189 | * @throws NetconfException when there is a problem in the communication process on |
| 190 | * the underlying connection |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 191 | * @deprecated - 1.10.0 Kingfisher use method overload that accepts |
| 192 | * org.onosproject.netconf.TargetConfig enum parameter instead |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 193 | */ |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 194 | @Deprecated |
| 195 | default String getConfig(TargetConfig netconfTargetConfig, String configurationFilterSchema) |
| 196 | throws NetconfException { |
| 197 | return getConfig(TargetConfig.toDatastoreId(netconfTargetConfig), |
| 198 | configurationFilterSchema); |
| 199 | } |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 200 | |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 201 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 202 | /** |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 203 | * Retrieves part of the specified configuration based on the filterSchema. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 204 | * |
| 205 | * @param newConfiguration configuration to set |
| 206 | * @return true if the configuration was edited correctly |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 207 | * @throws NetconfException when there is a problem in the communication process on |
| 208 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 209 | */ |
| 210 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 211 | boolean editConfig(String newConfiguration) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 212 | |
| 213 | /** |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 214 | * Retrieves part of the specified configuration based on the filterSchema. |
| 215 | * |
| 216 | * @param netconfTargetConfig the targetConfiguration to change |
| 217 | * @param mode selected mode to change the configuration |
| 218 | * @param newConfiguration configuration to set |
| 219 | * @return true if the configuration was edited correctly |
| 220 | * @throws NetconfException when there is a problem in the communication process on |
| 221 | * the underlying connection |
| 222 | */ |
| 223 | default boolean editConfig(DatastoreId netconfTargetConfig, String mode, String newConfiguration) |
| 224 | throws NetconfException { |
| 225 | // default implementation provided for backward compatibility |
| 226 | // this API is the one, which should be implemented |
| 227 | // TODO default implementation here should be removed after |
| 228 | // deprecation of the other 2 variants. |
| 229 | return editConfig(netconfTargetConfig.id(), mode, newConfiguration); |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Retrieves part of the specified configuration based on the filterSchema. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 234 | * |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 235 | * @param netconfTargetConfig the targetConfiguration to change |
| 236 | * @param mode selected mode to change the configuration |
| 237 | * @param newConfiguration configuration to set |
| 238 | * @return true if the configuration was edited correctly |
| 239 | * @throws NetconfException when there is a problem in the communication process on |
| 240 | * the underlying connection |
| 241 | * @deprecated - 1.10.0 Kingfisher use method overload that accepts |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 242 | * org.onosproject.netconf.TargetConfiguration enum parameter instead |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 243 | */ |
| 244 | @Deprecated |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 245 | default boolean editConfig(String netconfTargetConfig, String mode, String newConfiguration) |
| 246 | throws NetconfException { |
| 247 | return editConfig(TargetConfig.toDatastoreId(netconfTargetConfig), |
| 248 | mode, |
| 249 | newConfiguration); |
| 250 | } |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 251 | |
| 252 | /** |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 253 | * Retrieves part of the specified configuration based on the filterSchema. |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 254 | * |
| 255 | * @param netconfTargetConfig the targetConfiguration to change |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 256 | * @param mode selected mode to change the configuration |
| 257 | * @param newConfiguration configuration to set |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 258 | * @return true if the configuration was edited correctly |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 259 | * @throws NetconfException when there is a problem in the communication process on |
| 260 | * the underlying connection |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 261 | * @deprecated - 1.10.0 Kingfisher use method overload that accepts |
| 262 | * org.onosproject.netconf.TargetConfiguration enum parameter instead |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 263 | */ |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 264 | @Deprecated |
| 265 | default boolean editConfig(TargetConfig netconfTargetConfig, String mode, String newConfiguration) |
| 266 | throws NetconfException { |
| 267 | return editConfig(TargetConfig.toDatastoreId(netconfTargetConfig), |
| 268 | mode, |
| 269 | newConfiguration); |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Copies the configuration between configuration datastores. |
| 274 | * <p> |
| 275 | * The target configuration can't be the running one |
| 276 | * |
| 277 | * @param destination configuration datastore |
| 278 | * @param source configuration datastore |
| 279 | * @return true if the configuration was copied correctly |
| 280 | * @throws NetconfException when there is a problem in the communication process on |
| 281 | * the underlying connection |
| 282 | */ |
| 283 | default boolean copyConfig(DatastoreId destination, DatastoreId source) |
| 284 | throws NetconfException { |
| 285 | // default implementation provided for backward compatibility |
| 286 | // but this API should be implemented overriding the default |
| 287 | // TODO default implementation here should be removed after |
| 288 | // deprecation of the other 2 variants. |
| 289 | return copyConfig(destination.id(), source.id()); |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Copies the new configuration, an Url or a complete configuration xml tree |
| 294 | * to the target configuration. |
| 295 | * The target configuration can't be the running one |
| 296 | * |
| 297 | * @param netconfTargetConfig the type of configuration to retrieve. |
| 298 | * @param newConfiguration configuration XML to set or URL tag to the configuration |
| 299 | * @return true if the configuration was copied correctly |
| 300 | * @throws NetconfException when there is a problem in the communication process on |
| 301 | * the underlying connection |
| 302 | */ |
| 303 | default boolean copyConfig(DatastoreId netconfTargetConfig, String newConfiguration) |
| 304 | throws NetconfException { |
| 305 | // default implementation provided for backward compatibility |
| 306 | // but this API should be implemented overriding the default |
| 307 | // TODO default implementation here should be removed after |
| 308 | // deprecation of the other 2 variants. |
| 309 | return copyConfig(netconfTargetConfig.id(), newConfiguration); |
| 310 | } |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 311 | |
| 312 | /** |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 313 | * Copies the new configuration, an Url or a complete configuration xml tree |
| 314 | * to the target configuration. |
| 315 | * The target configuration can't be the running one |
| 316 | * |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 317 | * @param netconfTargetConfig the type of configuration to retrieve. |
| 318 | * @param newConfiguration configuration to set |
| 319 | * @return true if the configuration was copied correctly |
| 320 | * @throws NetconfException when there is a problem in the communication process on |
| 321 | * the underlying connection |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 322 | */ |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 323 | boolean copyConfig(String netconfTargetConfig, String newConfiguration) |
| 324 | throws NetconfException; |
| 325 | |
| 326 | /** |
| 327 | * Copies the new configuration, an Url or a complete configuration xml tree |
| 328 | * to the target configuration. |
| 329 | * The target configuration can't be the running one |
| 330 | * |
| 331 | * @param netconfTargetConfig the type of configuration to retrieve. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 332 | * @param newConfiguration configuration to set |
| 333 | * @return true if the configuration was copied correctly |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 334 | * @throws NetconfException when there is a problem in the communication process on |
| 335 | * the underlying connection |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 336 | * @deprecated - 1.10.0 Kingfisher use method overload that accepts |
| 337 | * org.onosproject.netconf.TargetConfiguration enum parameter instead |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 338 | */ |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 339 | @Deprecated |
| 340 | default boolean copyConfig(TargetConfig netconfTargetConfig, String newConfiguration) |
| 341 | throws NetconfException { |
| 342 | return copyConfig(TargetConfig.toDatastoreId(netconfTargetConfig), newConfiguration); |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * Deletes part of the specified configuration based on the filterSchema. |
| 347 | * |
| 348 | * @param netconfTargetConfig the name of the configuration to delete |
| 349 | * @return true if the configuration was copied correctly |
| 350 | * @throws NetconfException when there is a problem in the communication process on |
| 351 | * the underlying connection |
| 352 | */ |
| 353 | default boolean deleteConfig(DatastoreId netconfTargetConfig) throws NetconfException { |
| 354 | // default implementation provided for backward compatibility |
| 355 | // this API is the one, which should be implemented |
| 356 | // TODO default implementation here should be removed after |
| 357 | // deprecation of the other 2 variants. |
| 358 | return deleteConfig(netconfTargetConfig.id()); |
| 359 | } |
| 360 | |
| 361 | /** |
| 362 | * Deletes part of the specified configuration based on the filterSchema. |
| 363 | * |
| 364 | * @param netconfTargetConfig the name of the configuration to delete |
| 365 | * @return true if the configuration was deleted correctly |
| 366 | * @throws NetconfException when there is a problem in the communication process on |
| 367 | * the underlying connection |
| 368 | * @deprecated - 1.10.0 Kingfisher use method overload that accepts |
| 369 | * org.onosproject.netconf.TargetConfiguration enum parameter instead |
| 370 | */ |
| 371 | @Deprecated |
| 372 | default boolean deleteConfig(String netconfTargetConfig) throws NetconfException { |
| 373 | return deleteConfig(TargetConfig.toDatastoreId(netconfTargetConfig)); |
| 374 | } |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 375 | |
| 376 | /** |
| 377 | * Deletes part of the specified configuration based on the filterSchema. |
| 378 | * |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 379 | * @param netconfTargetConfig the name of the configuration to delete |
| 380 | * @return true if the configuration was copied correctly |
| 381 | * @throws NetconfException when there is a problem in the communication process on |
| 382 | * the underlying connection |
| 383 | * @deprecated - 1.10.0 Kingfisher use method overload that accepts |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 384 | * org.onosproject.netconf.TargetConfiguration enum parameter instead |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 385 | */ |
| 386 | @Deprecated |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 387 | default boolean deleteConfig(TargetConfig netconfTargetConfig) throws NetconfException { |
| 388 | return deleteConfig(TargetConfig.toDatastoreId(netconfTargetConfig)); |
| 389 | } |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 390 | |
| 391 | /** |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 392 | * Starts subscription to the device's notifications. |
| 393 | * |
| 394 | * @throws NetconfException when there is a problem starting the subscription |
| 395 | */ |
| 396 | void startSubscription() throws NetconfException; |
| 397 | |
| 398 | /** |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 399 | * Starts subscription to the device's notifications. |
| 400 | * |
| 401 | * @param filterSchema XML subtrees to indicate specific notification |
| 402 | * @throws NetconfException when there is a problem starting the subscription |
| 403 | */ |
| 404 | @Beta |
| 405 | void startSubscription(String filterSchema) throws NetconfException; |
| 406 | |
| 407 | /** |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 408 | * Ends subscription to the device's notifications. |
| 409 | * |
| 410 | * @throws NetconfException when there is a problem ending the subscription |
| 411 | */ |
| 412 | void endSubscription() throws NetconfException; |
| 413 | |
| 414 | /** |
| 415 | * Locks the specified configuration. |
| 416 | * |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 417 | * @param datastore configuration datastore to be locked |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 418 | * @return true if successful. |
| 419 | * @throws NetconfException when there is a problem in the communication process on |
| 420 | * the underlying connection |
| 421 | */ |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 422 | default boolean lock(DatastoreId datastore) throws NetconfException { |
| 423 | // default implementation provided for backward compatibility |
| 424 | // this API is the one, which should be implemented |
| 425 | // TODO default implementation here should be removed after |
| 426 | // deprecation of the other 2 variants. |
| 427 | return lock(datastore.id()); |
| 428 | } |
| 429 | |
| 430 | /** |
| 431 | * Locks the specified configuration. |
| 432 | * |
| 433 | * @param configType type of configuration to be locked |
| 434 | * @return true if successful. |
| 435 | * @throws NetconfException when there is a problem in the communication process on |
| 436 | * the underlying connection |
| 437 | * @deprecated - 1.10.0 Kingfisher use method overload that accepts |
| 438 | * org.onosproject.netconf.TargetConfiguration parameter instead |
| 439 | */ |
| 440 | @Deprecated |
| 441 | default boolean lock(String configType) throws NetconfException { |
| 442 | return lock(TargetConfig.toDatastoreId(configType)); |
| 443 | } |
| 444 | |
| 445 | /** |
| 446 | * Unlocks the specified configuration. |
| 447 | * |
| 448 | * @param datastore configuration datastore to be unlocked |
| 449 | * @return true if successful. |
| 450 | * @throws NetconfException when there is a problem in the communication process on |
| 451 | * the underlying connection |
| 452 | */ |
| 453 | default boolean unlock(DatastoreId datastore) throws NetconfException { |
| 454 | // default implementation provided for backward compatibility |
| 455 | // this API is the one, which should be implemented |
| 456 | // TODO default implementation here should be removed after |
| 457 | // deprecation of the other 2 variants. |
| 458 | return unlock(datastore.id()); |
| 459 | } |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 460 | |
| 461 | /** |
| 462 | * Unlocks the specified configuration. |
| 463 | * |
| 464 | * @param configType type of configuration to be locked |
| 465 | * @return true if successful. |
| 466 | * @throws NetconfException when there is a problem in the communication process on |
| 467 | * the underlying connection |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 468 | * @deprecated - 1.10.0 Kingfisher use method overload that accepts |
| 469 | * org.onosproject.netconf.TargetConfiguration parameter instead |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 470 | */ |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 471 | @Deprecated |
| 472 | default boolean unlock(String configType) throws NetconfException { |
| 473 | return unlock(TargetConfig.toDatastoreId(configType)); |
| 474 | } |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 475 | |
| 476 | /** |
| 477 | * Locks the running configuration. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 478 | * |
| 479 | * @return true if successful. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 480 | * @throws NetconfException when there is a problem in the communication process on |
| 481 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 482 | */ |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 483 | default boolean lock() throws NetconfException { |
| 484 | return lock(DatastoreId.RUNNING); |
| 485 | } |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 486 | |
| 487 | /** |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 488 | * Unlocks the running configuration. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 489 | * |
| 490 | * @return true if successful. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 491 | * @throws NetconfException when there is a problem in the communication process on |
| 492 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 493 | */ |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 494 | default boolean unlock() throws NetconfException { |
| 495 | return unlock(DatastoreId.RUNNING); |
| 496 | } |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 497 | |
| 498 | /** |
| 499 | * Closes the Netconf session with the device. |
| 500 | * the first time it tries gracefully, then kills it forcefully |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 501 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 502 | * @return true if closed |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 503 | * @throws NetconfException when there is a problem in the communication process on |
| 504 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 505 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 506 | boolean close() throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 507 | |
| 508 | /** |
| 509 | * Gets the session ID of the Netconf session. |
| 510 | * |
| 511 | * @return Session ID as a string. |
| 512 | */ |
| 513 | String getSessionId(); |
| 514 | |
| 515 | /** |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 516 | * Gets the capabilities of the remote Netconf device associated to this |
| 517 | * session. |
| 518 | * |
| 519 | * @return Network capabilities as strings in a Set. |
| 520 | * |
| 521 | * @since 1.10.0 |
| 522 | * Note: default implementation provided with the interface |
| 523 | * will be removed when {@code getServerCapabilities()} reaches |
| 524 | * deprecation grace period. |
| 525 | */ |
| 526 | default Set<String> getDeviceCapabilitiesSet() { |
| 527 | // default implementation should be removed in the future |
| 528 | Set<String> capabilities = new LinkedHashSet<>(); |
| 529 | Matcher capabilityMatcher = |
| 530 | Pattern.compile("<capability>\\s*(.*?)\\s*</capability>") |
| 531 | .matcher(getServerCapabilities()); |
| 532 | while (capabilityMatcher.find()) { |
| 533 | capabilities.add(capabilityMatcher.group(1)); |
| 534 | } |
| 535 | return capabilities; |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * Gets the capabilities of the Netconf server (remote device) associated |
| 540 | * to this session. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 541 | * |
| 542 | * @return Network capabilities as a string. |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 543 | * @deprecated 1.10.0 use {@link #getDeviceCapabilitiesSet()} instead |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 544 | */ |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 545 | @Deprecated |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 546 | String getServerCapabilities(); |
| 547 | |
| 548 | /** |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 549 | * Sets the ONOS side capabilities. |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 550 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 551 | * @param capabilities list of capabilities the device has. |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 552 | * @deprecated 1.10.0 use {@link #setOnosCapabilities(Iterable)} instead |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 553 | */ |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 554 | @Deprecated |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 555 | void setDeviceCapabilities(List<String> capabilities); |
| 556 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 557 | /** |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 558 | * Checks the state of the underlying SSH session and connection |
| 559 | * and if necessary it reestablishes it. |
| 560 | * Should be implemented, providing a default here for retrocompatibility. |
| 561 | * @throws NetconfException when there is a problem in reestablishing |
| 562 | * the connection or the session to the device. |
| 563 | */ |
| 564 | |
| 565 | default void checkAndReestablish() throws NetconfException { |
| 566 | Logger log = LoggerFactory.getLogger(NetconfSession.class); |
| 567 | log.error("Not implemented/exposed by the underlying session implementation"); |
| 568 | } |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 569 | |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 570 | /** |
| 571 | * Sets the ONOS side capabilities. |
| 572 | * |
| 573 | * @param capabilities list of capabilities ONOS has. |
| 574 | * |
| 575 | * @since 1.10.0 |
| 576 | */ |
| 577 | default void setOnosCapabilities(Iterable<String> capabilities) { |
| 578 | // default implementation should be removed in the future |
| 579 | // no-op |
| 580 | } |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 581 | |
| 582 | /** |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 583 | * Remove a listener from the underlying stream handler implementation. |
| 584 | * |
| 585 | * @param listener event listener. |
| 586 | */ |
| 587 | void addDeviceOutputListener(NetconfDeviceOutputEventListener listener); |
| 588 | |
| 589 | /** |
| 590 | * Remove a listener from the underlying stream handler implementation. |
| 591 | * |
| 592 | * @param listener event listener. |
| 593 | */ |
| 594 | void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener); |
| 595 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 596 | } |