blob: 06c8b9c1162517240113986ea1b32e1021657cd9 [file] [log] [blame]
andreaeb70a942015-10-16 21:34:46 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
andreaeb70a942015-10-16 21:34:46 -07003 *
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
17package org.onosproject.netconf;
18
Akihiro Yamanouchi45122222016-07-15 13:13:11 +090019import com.google.common.annotations.Beta;
Andrea Campanellac3627842017-04-04 18:06:54 +020020import org.slf4j.Logger;
21import org.slf4j.LoggerFactory;
Andrei Mihaescuac542ca2017-03-26 21:36:25 +030022
Aaron Kruglikov72db6422017-02-13 12:16:51 -080023import java.util.LinkedHashSet;
andreaeb70a942015-10-16 21:34:46 -070024import java.util.List;
Aaron Kruglikov72db6422017-02-13 12:16:51 -080025import java.util.Set;
Andrea Campanella101417d2015-12-11 17:58:07 -080026import java.util.concurrent.CompletableFuture;
Aaron Kruglikov72db6422017-02-13 12:16:51 -080027import java.util.regex.Matcher;
28import java.util.regex.Pattern;
andreaeb70a942015-10-16 21:34:46 -070029
30/**
31 * NETCONF session object that allows NETCONF operations on top with the physical
32 * device on top of an SSH connection.
33 */
Sean Condond2c8d472017-02-17 17:09:39 +000034// TODO change return type of methods to <Capability, XMLdoc, string or yang obj>
andreaeb70a942015-10-16 21:34:46 -070035public interface NetconfSession {
36
37 /**
Andrea Campanella101417d2015-12-11 17:58:07 -080038 * Executes an asynchronous RPC to the server and obtains a future to be completed.
39 *
Sean Condond2c8d472017-02-17 17:09:39 +000040 * 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 Campanella101417d2015-12-11 17:58:07 -080044 * @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 Condond2c8d472017-02-17 17:09:39 +000049 @Deprecated
Andrea Campanella101417d2015-12-11 17:58:07 -080050 CompletableFuture<String> request(String request) throws NetconfException;
51
52
53 /**
Sean Condond2c8d472017-02-17 17:09:39 +000054 * Retrieves the requested configuration, different from get-config.
Andrea Campanellaf4fd0352015-12-14 17:03:05 -080055 *
andreaeb70a942015-10-16 21:34:46 -070056 * @param request the XML containing the request to the server.
57 * @return device running configuration
Andrea Campanella101417d2015-12-11 17:58:07 -080058 * @throws NetconfException when there is a problem in the communication process on
59 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -070060 */
Andrea Campanella101417d2015-12-11 17:58:07 -080061 String get(String request) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -070062
63 /**
Sean Condond2c8d472017-02-17 17:09:39 +000064 * Retrieves the requested data.
Akihiro Yamanouchi5e5d4df2016-06-08 17:06:33 +090065 *
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 Yamanouchi45122222016-07-15 13:13:11 +090076 * Executes an synchronous RPC to the server and wrap the request in RPC header.
Akihiro Yamanouchi8d3a9d32016-07-12 11:41:44 +090077 *
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 Campanella101417d2015-12-11 17:58:07 -080086 * Executes an synchronous RPC to the server.
Andrea Campanellaf4fd0352015-12-14 17:03:05 -080087 *
andreaeb70a942015-10-16 21:34:46 -070088 * @param request the XML containing the RPC for the server.
89 * @return Server response or ERROR
Andrea Campanella101417d2015-12-11 17:58:07 -080090 * @throws NetconfException when there is a problem in the communication process on
91 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -070092 */
Andrea Campanella101417d2015-12-11 17:58:07 -080093 String requestSync(String request) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -070094
95 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -070096 * Retrieves the specified configuration.
andreaeb70a942015-10-16 21:34:46 -070097 *
Andrei Mihaescuac542ca2017-03-26 21:36:25 +030098 * @param netconfTargetConfig the type of configuration to retrieve.
andreaeb70a942015-10-16 21:34:46 -070099 * @return specified configuration.
Andrea Campanella101417d2015-12-11 17:58:07 -0800100 * @throws NetconfException when there is a problem in the communication process on
101 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700102 */
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700103 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 Mihaescuac542ca2017-03-26 21:36:25 +0300110
111 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700112 * Retrieves the specified configuration.
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300113 *
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 HIGUCHI89111d92017-05-04 11:29:17 -0700119 * org.onosproject.netconf.TargetConfiguration parameter instead
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300120 */
121 @Deprecated
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700122 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 Mihaescuac542ca2017-03-26 21:36:25 +0300140
andreaeb70a942015-10-16 21:34:46 -0700141
142 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700143 * 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.
andreaeb70a942015-10-16 21:34:46 -0700165 *
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300166 * @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 HIGUCHI89111d92017-05-04 11:29:17 -0700176 default String getConfig(String netconfTargetConfig, String configurationFilterSchema)
177 throws NetconfException {
178 return getConfig(TargetConfig.toDatastoreId(netconfTargetConfig),
179 configurationFilterSchema);
180 }
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300181
182 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700183 * Retrieves part of the specified configuration based on the filterSchema.
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300184 *
185 * @param netconfTargetConfig the type of configuration to retrieve.
andreaeb70a942015-10-16 21:34:46 -0700186 * @param configurationFilterSchema XML schema to filter the configuration
187 * elements we are interested in
188 * @return device running configuration.
Andrea Campanella101417d2015-12-11 17:58:07 -0800189 * @throws NetconfException when there is a problem in the communication process on
190 * the underlying connection
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700191 * @deprecated - 1.10.0 Kingfisher use method overload that accepts
192 * org.onosproject.netconf.TargetConfig enum parameter instead
andreaeb70a942015-10-16 21:34:46 -0700193 */
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700194 @Deprecated
195 default String getConfig(TargetConfig netconfTargetConfig, String configurationFilterSchema)
196 throws NetconfException {
197 return getConfig(TargetConfig.toDatastoreId(netconfTargetConfig),
198 configurationFilterSchema);
199 }
andreaeb70a942015-10-16 21:34:46 -0700200
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300201
andreaeb70a942015-10-16 21:34:46 -0700202 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700203 * Retrieves part of the specified configuration based on the filterSchema.
andreaeb70a942015-10-16 21:34:46 -0700204 *
205 * @param newConfiguration configuration to set
206 * @return true if the configuration was edited correctly
Andrea Campanella101417d2015-12-11 17:58:07 -0800207 * @throws NetconfException when there is a problem in the communication process on
208 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700209 */
210
Andrea Campanella101417d2015-12-11 17:58:07 -0800211 boolean editConfig(String newConfiguration) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700212
213 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700214 * 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 Campanella101417d2015-12-11 17:58:07 -0800234 *
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300235 * @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 HIGUCHI89111d92017-05-04 11:29:17 -0700242 * org.onosproject.netconf.TargetConfiguration enum parameter instead
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300243 */
244 @Deprecated
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700245 default boolean editConfig(String netconfTargetConfig, String mode, String newConfiguration)
246 throws NetconfException {
247 return editConfig(TargetConfig.toDatastoreId(netconfTargetConfig),
248 mode,
249 newConfiguration);
250 }
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300251
252 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700253 * Retrieves part of the specified configuration based on the filterSchema.
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300254 *
255 * @param netconfTargetConfig the targetConfiguration to change
Andrea Campanella101417d2015-12-11 17:58:07 -0800256 * @param mode selected mode to change the configuration
257 * @param newConfiguration configuration to set
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800258 * @return true if the configuration was edited correctly
Andrea Campanella101417d2015-12-11 17:58:07 -0800259 * @throws NetconfException when there is a problem in the communication process on
260 * the underlying connection
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700261 * @deprecated - 1.10.0 Kingfisher use method overload that accepts
262 * org.onosproject.netconf.TargetConfiguration enum parameter instead
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800263 */
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700264 @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 Campanellaf4fd0352015-12-14 17:03:05 -0800311
312 /**
andreaeb70a942015-10-16 21:34:46 -0700313 * 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 Mihaescuac542ca2017-03-26 21:36:25 +0300317 * @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 Mihaescuac542ca2017-03-26 21:36:25 +0300322 */
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300323 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.
andreaeb70a942015-10-16 21:34:46 -0700332 * @param newConfiguration configuration to set
333 * @return true if the configuration was copied correctly
Andrea Campanella101417d2015-12-11 17:58:07 -0800334 * @throws NetconfException when there is a problem in the communication process on
335 * the underlying connection
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700336 * @deprecated - 1.10.0 Kingfisher use method overload that accepts
337 * org.onosproject.netconf.TargetConfiguration enum parameter instead
andreaeb70a942015-10-16 21:34:46 -0700338 */
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700339 @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 }
andreaeb70a942015-10-16 21:34:46 -0700375
376 /**
377 * Deletes part of the specified configuration based on the filterSchema.
378 *
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300379 * @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 HIGUCHI89111d92017-05-04 11:29:17 -0700384 * org.onosproject.netconf.TargetConfiguration enum parameter instead
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300385 */
386 @Deprecated
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700387 default boolean deleteConfig(TargetConfig netconfTargetConfig) throws NetconfException {
388 return deleteConfig(TargetConfig.toDatastoreId(netconfTargetConfig));
389 }
andreaeb70a942015-10-16 21:34:46 -0700390
391 /**
helenyrwu0407c642016-06-09 12:01:30 -0700392 * 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 Yamanouchi45122222016-07-15 13:13:11 +0900399 * 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 /**
helenyrwu0407c642016-06-09 12:01:30 -0700408 * 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 HIGUCHI89111d92017-05-04 11:29:17 -0700417 * @param datastore configuration datastore to be locked
helenyrwu0407c642016-06-09 12:01:30 -0700418 * @return true if successful.
419 * @throws NetconfException when there is a problem in the communication process on
420 * the underlying connection
421 */
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700422 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 }
helenyrwu0407c642016-06-09 12:01:30 -0700460
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 HIGUCHI89111d92017-05-04 11:29:17 -0700468 * @deprecated - 1.10.0 Kingfisher use method overload that accepts
469 * org.onosproject.netconf.TargetConfiguration parameter instead
helenyrwu0407c642016-06-09 12:01:30 -0700470 */
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700471 @Deprecated
472 default boolean unlock(String configType) throws NetconfException {
473 return unlock(TargetConfig.toDatastoreId(configType));
474 }
helenyrwu0407c642016-06-09 12:01:30 -0700475
476 /**
477 * Locks the running configuration.
andreaeb70a942015-10-16 21:34:46 -0700478 *
479 * @return true if successful.
Andrea Campanella101417d2015-12-11 17:58:07 -0800480 * @throws NetconfException when there is a problem in the communication process on
481 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700482 */
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700483 default boolean lock() throws NetconfException {
484 return lock(DatastoreId.RUNNING);
485 }
andreaeb70a942015-10-16 21:34:46 -0700486
487 /**
helenyrwu0407c642016-06-09 12:01:30 -0700488 * Unlocks the running configuration.
andreaeb70a942015-10-16 21:34:46 -0700489 *
490 * @return true if successful.
Andrea Campanella101417d2015-12-11 17:58:07 -0800491 * @throws NetconfException when there is a problem in the communication process on
492 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700493 */
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700494 default boolean unlock() throws NetconfException {
495 return unlock(DatastoreId.RUNNING);
496 }
andreaeb70a942015-10-16 21:34:46 -0700497
498 /**
499 * Closes the Netconf session with the device.
500 * the first time it tries gracefully, then kills it forcefully
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800501 *
andreaeb70a942015-10-16 21:34:46 -0700502 * @return true if closed
Andrea Campanella101417d2015-12-11 17:58:07 -0800503 * @throws NetconfException when there is a problem in the communication process on
504 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700505 */
Andrea Campanella101417d2015-12-11 17:58:07 -0800506 boolean close() throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700507
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 Kruglikov72db6422017-02-13 12:16:51 -0800516 * 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.
andreaeb70a942015-10-16 21:34:46 -0700541 *
542 * @return Network capabilities as a string.
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800543 * @deprecated 1.10.0 use {@link #getDeviceCapabilitiesSet()} instead
andreaeb70a942015-10-16 21:34:46 -0700544 */
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800545 @Deprecated
andreaeb70a942015-10-16 21:34:46 -0700546 String getServerCapabilities();
547
548 /**
Andrea Campanella101417d2015-12-11 17:58:07 -0800549 * Sets the ONOS side capabilities.
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800550 *
andreaeb70a942015-10-16 21:34:46 -0700551 * @param capabilities list of capabilities the device has.
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800552 * @deprecated 1.10.0 use {@link #setOnosCapabilities(Iterable)} instead
andreaeb70a942015-10-16 21:34:46 -0700553 */
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800554 @Deprecated
andreaeb70a942015-10-16 21:34:46 -0700555 void setDeviceCapabilities(List<String> capabilities);
556
Andrea Campanella101417d2015-12-11 17:58:07 -0800557 /**
Andrea Campanellac3627842017-04-04 18:06:54 +0200558 * 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 HIGUCHI89111d92017-05-04 11:29:17 -0700569
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800570 /**
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 Campanellac3627842017-04-04 18:06:54 +0200581
582 /**
Andrea Campanella101417d2015-12-11 17:58:07 -0800583 * 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
Sean Condon54d82432017-07-26 22:27:25 +0100596 /**
597 * Read the connect timeout that this session was created with.
598 * @return timeout in seconds
599 */
600 default int timeoutConnectSec() {
601 return 0;
602 };
603
604 /**
605 * Read the reply timeout that this session was created with.
606 * @return timeout in seconds
607 */
608 default int timeoutReplySec() {
609 return 0;
610 };
611
612 /**
613 * Read the idle timeout that this session was created with.
614 * @return timeout in seconds
615 */
616 default int timeoutIdleSec() {
617 return 0;
618 };
619
andreaeb70a942015-10-16 21:34:46 -0700620}