blob: 41ec065afa5ff2e2e467ef662f010f6fbef4bb9a [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.Set;
Andrea Campanella101417d2015-12-11 17:58:07 -080024import java.util.concurrent.CompletableFuture;
andreaeb70a942015-10-16 21:34:46 -070025
26/**
27 * NETCONF session object that allows NETCONF operations on top with the physical
28 * device on top of an SSH connection.
29 */
Sean Condond2c8d472017-02-17 17:09:39 +000030// TODO change return type of methods to <Capability, XMLdoc, string or yang obj>
andreaeb70a942015-10-16 21:34:46 -070031public interface NetconfSession {
32
33 /**
Andrea Campanella101417d2015-12-11 17:58:07 -080034 * Executes an asynchronous RPC to the server and obtains a future to be completed.
35 *
Sean Condond2c8d472017-02-17 17:09:39 +000036 * The caller must ensure that the message-id in any request is unique
37 * for the session
38 *
39 * @deprecated - 1.10.0 do not remove needs reworking
Andrea Campanella101417d2015-12-11 17:58:07 -080040 * @param request the XML containing the RPC for the server.
41 * @return Server response or ERROR
42 * @throws NetconfException when there is a problem in the communication process on
43 * the underlying connection
44 */
Sean Condond2c8d472017-02-17 17:09:39 +000045 @Deprecated
Andrea Campanella101417d2015-12-11 17:58:07 -080046 CompletableFuture<String> request(String request) throws NetconfException;
47
Yuta HIGUCHI6e6c26e2017-09-06 14:25:57 -070048 /**
49 * Executes an asynchronous RPC request to the server and obtains a future
50 * for it's response.
51 *
52 * @param request the XML containing the RPC request for the server.
53 * @return Server response or ERROR
54 * @throws NetconfException when there is a problem in the communication process on
55 * the underlying connection
56 * @throws NetconfTransportException on secure transport-layer error
57 */
Yuta HIGUCHI4f55c672018-06-14 18:10:43 -070058 CompletableFuture<String> rpc(String request) throws NetconfException;
Yuta HIGUCHI6e6c26e2017-09-06 14:25:57 -070059
Yuta HIGUCHI5ac34432018-02-13 16:29:15 -080060 /**
61 * Retrieves the specified configuration.
62 *
63 * @param datastore to retrieve configuration from
64 * @return specified configuration
65 *
66 * @throws NetconfException when there is a problem in the communication process on
67 * the underlying connection
68 */
Yuta HIGUCHI4f55c672018-06-14 18:10:43 -070069 CompletableFuture<CharSequence> asyncGetConfig(DatastoreId datastore) throws NetconfException;
Yuta HIGUCHI5ac34432018-02-13 16:29:15 -080070
71 /**
72 * Retrieves running configuration and device state.
73 *
74 * @return running configuration and device state
75 *
76 * @throws NetconfException when there is a problem in the communication process on
77 * the underlying connection
78 */
Yuta HIGUCHI4f55c672018-06-14 18:10:43 -070079 CompletableFuture<CharSequence> asyncGet() throws NetconfException;
Yuta HIGUCHI5ac34432018-02-13 16:29:15 -080080
Andrea Campanella101417d2015-12-11 17:58:07 -080081
82 /**
Sean Condond2c8d472017-02-17 17:09:39 +000083 * Retrieves the requested configuration, different from get-config.
Andrea Campanellaf4fd0352015-12-14 17:03:05 -080084 *
andreaeb70a942015-10-16 21:34:46 -070085 * @param request the XML containing the request to the server.
86 * @return device running configuration
Andrea Campanella101417d2015-12-11 17:58:07 -080087 * @throws NetconfException when there is a problem in the communication process on
88 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -070089 */
Andrea Campanella101417d2015-12-11 17:58:07 -080090 String get(String request) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -070091
92 /**
Sean Condond2c8d472017-02-17 17:09:39 +000093 * Retrieves the requested data.
Akihiro Yamanouchi5e5d4df2016-06-08 17:06:33 +090094 *
95 * @param filterSchema XML subtrees to include in the reply
96 * @param withDefaultsMode with-defaults mode
97 * @return Server response
98 * @throws NetconfException when there is a problem in the communication process on
99 * the underlying connection
100 */
101 String get(String filterSchema, String withDefaultsMode)
102 throws NetconfException;
103
104 /**
Akihiro Yamanouchi45122222016-07-15 13:13:11 +0900105 * Executes an synchronous RPC to the server and wrap the request in RPC header.
Akihiro Yamanouchi8d3a9d32016-07-12 11:41:44 +0900106 *
107 * @param request the XML containing the request to the server.
108 * @return Server response or ERROR
109 * @throws NetconfException when there is a problem in the communication process on
110 * the underlying connection
111 */
112 String doWrappedRpc(String request) throws NetconfException;
113
114 /**
Andrea Campanella101417d2015-12-11 17:58:07 -0800115 * Executes an synchronous RPC to the server.
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800116 *
andreaeb70a942015-10-16 21:34:46 -0700117 * @param request the XML containing the RPC for the server.
118 * @return Server response or ERROR
Andrea Campanella101417d2015-12-11 17:58:07 -0800119 * @throws NetconfException when there is a problem in the communication process on
120 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700121 */
Andrea Campanella101417d2015-12-11 17:58:07 -0800122 String requestSync(String request) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700123
124 /**
gyewan.an91d7e7e2019-01-17 15:12:48 +0900125 * Executes an synchronous RPC to the server with specific reply TIMEOUT.
126 *
127 * @param request the XML containing the RPC for the server.
128 * @param timeout the reply timeout.
129 * @return Server response or ERROR
130 * @throws NetconfException when there is a problem in the communication process on
131 * the underlying connection
132 */
133 default String requestSync(String request, int timeout) throws NetconfException {
134 return "";
135 }
136
137 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700138 * Retrieves the specified configuration.
andreaeb70a942015-10-16 21:34:46 -0700139 *
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300140 * @param netconfTargetConfig the type of configuration to retrieve.
andreaeb70a942015-10-16 21:34:46 -0700141 * @return specified configuration.
Andrea Campanella101417d2015-12-11 17:58:07 -0800142 * @throws NetconfException when there is a problem in the communication process on
143 * the underlying connection
Yuta HIGUCHI5ac34432018-02-13 16:29:15 -0800144 *
145 * @deprecated in 1.13.0 use async version instead.
andreaeb70a942015-10-16 21:34:46 -0700146 */
Yuta HIGUCHI5ac34432018-02-13 16:29:15 -0800147 @Deprecated
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700148 String getConfig(DatastoreId netconfTargetConfig) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700149
150 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700151 * Retrieves part of the specified configuration based on the filterSchema.
152 *
153 * @param netconfTargetConfig the type of configuration to retrieve.
154 * @param configurationFilterSchema XML schema to filter the configuration
155 * elements we are interested in
156 * @return device running configuration.
157 * @throws NetconfException when there is a problem in the communication process on
158 * the underlying connection
159 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700160 String getConfig(DatastoreId netconfTargetConfig,
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700161 String configurationFilterSchema)
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700162 throws NetconfException;
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300163
andreaeb70a942015-10-16 21:34:46 -0700164 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700165 * Retrieves part of the specified configuration based on the filterSchema.
andreaeb70a942015-10-16 21:34:46 -0700166 *
167 * @param newConfiguration configuration to set
168 * @return true if the configuration was edited correctly
Andrea Campanella101417d2015-12-11 17:58:07 -0800169 * @throws NetconfException when there is a problem in the communication process on
170 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700171 */
Andrea Campanella101417d2015-12-11 17:58:07 -0800172 boolean editConfig(String newConfiguration) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700173
174 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700175 * Retrieves part of the specified configuration based on the filterSchema.
176 *
177 * @param netconfTargetConfig the targetConfiguration to change
Yuta HIGUCHIe34c9c22017-12-04 17:47:14 -0800178 * @param mode default-operation mode
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700179 * @param newConfiguration configuration to set
180 * @return true if the configuration was edited correctly
181 * @throws NetconfException when there is a problem in the communication process on
182 * the underlying connection
183 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700184 boolean editConfig(DatastoreId netconfTargetConfig, String mode, String newConfiguration)
185 throws NetconfException;
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700186
187 /**
188 * Copies the configuration between configuration datastores.
189 * <p>
190 * The target configuration can't be the running one
191 *
192 * @param destination configuration datastore
193 * @param source configuration datastore
194 * @return true if the configuration was copied correctly
195 * @throws NetconfException when there is a problem in the communication process on
196 * the underlying connection
197 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700198 boolean copyConfig(DatastoreId destination, DatastoreId source)
199 throws NetconfException;
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700200
201 /**
202 * Copies the new configuration, an Url or a complete configuration xml tree
203 * to the target configuration.
204 * The target configuration can't be the running one
205 *
206 * @param netconfTargetConfig the type of configuration to retrieve.
207 * @param newConfiguration configuration XML to set or URL tag to the configuration
208 * @return true if the configuration was copied correctly
209 * @throws NetconfException when there is a problem in the communication process on
210 * the underlying connection
211 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700212 boolean copyConfig(DatastoreId netconfTargetConfig, String newConfiguration)
213 throws NetconfException;
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800214
215 /**
andreaeb70a942015-10-16 21:34:46 -0700216 * Copies the new configuration, an Url or a complete configuration xml tree
217 * to the target configuration.
218 * The target configuration can't be the running one
219 *
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300220 * @param netconfTargetConfig the type of configuration to retrieve.
221 * @param newConfiguration configuration to set
222 * @return true if the configuration was copied correctly
223 * @throws NetconfException when there is a problem in the communication process on
224 * the underlying connection
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300225 */
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300226 boolean copyConfig(String netconfTargetConfig, String newConfiguration)
227 throws NetconfException;
228
229 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700230 * Deletes part of the specified configuration based on the filterSchema.
231 *
232 * @param netconfTargetConfig the name of the configuration to delete
233 * @return true if the configuration was copied correctly
234 * @throws NetconfException when there is a problem in the communication process on
235 * the underlying connection
236 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700237 boolean deleteConfig(DatastoreId netconfTargetConfig) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700238
239 /**
helenyrwu0407c642016-06-09 12:01:30 -0700240 * Starts subscription to the device's notifications.
241 *
242 * @throws NetconfException when there is a problem starting the subscription
243 */
244 void startSubscription() throws NetconfException;
245
246 /**
Akihiro Yamanouchi45122222016-07-15 13:13:11 +0900247 * Starts subscription to the device's notifications.
248 *
249 * @param filterSchema XML subtrees to indicate specific notification
250 * @throws NetconfException when there is a problem starting the subscription
251 */
252 @Beta
253 void startSubscription(String filterSchema) throws NetconfException;
254
255 /**
helenyrwu0407c642016-06-09 12:01:30 -0700256 * Ends subscription to the device's notifications.
257 *
258 * @throws NetconfException when there is a problem ending the subscription
259 */
260 void endSubscription() throws NetconfException;
261
262 /**
263 * Locks the specified configuration.
264 *
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700265 * @param datastore configuration datastore to be locked
helenyrwu0407c642016-06-09 12:01:30 -0700266 * @return true if successful.
267 * @throws NetconfException when there is a problem in the communication process on
268 * the underlying connection
269 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700270 boolean lock(DatastoreId datastore) throws NetconfException;
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700271
272 /**
273 * Unlocks the specified configuration.
274 *
275 * @param datastore configuration datastore to be unlocked
276 * @return true if successful.
277 * @throws NetconfException when there is a problem in the communication process on
278 * the underlying connection
279 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700280 boolean unlock(DatastoreId datastore) throws NetconfException;
helenyrwu0407c642016-06-09 12:01:30 -0700281
282 /**
283 * Locks the running configuration.
andreaeb70a942015-10-16 21:34:46 -0700284 *
285 * @return true if successful.
Andrea Campanella101417d2015-12-11 17:58:07 -0800286 * @throws NetconfException when there is a problem in the communication process on
287 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700288 */
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700289 default boolean lock() throws NetconfException {
290 return lock(DatastoreId.RUNNING);
291 }
andreaeb70a942015-10-16 21:34:46 -0700292
293 /**
helenyrwu0407c642016-06-09 12:01:30 -0700294 * Unlocks the running configuration.
andreaeb70a942015-10-16 21:34:46 -0700295 *
296 * @return true if successful.
Andrea Campanella101417d2015-12-11 17:58:07 -0800297 * @throws NetconfException when there is a problem in the communication process on
298 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700299 */
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700300 default boolean unlock() throws NetconfException {
301 return unlock(DatastoreId.RUNNING);
302 }
andreaeb70a942015-10-16 21:34:46 -0700303
304 /**
Andrea Campanella3a361452019-08-02 10:17:53 +0200305 * Commits the candidate configuration the running configuration.
306 *
307 * @return true if successful.
308 * @throws NetconfException when there is a problem in the communication process on
309 * the underlying connection
310 */
311 default boolean commit() throws NetconfException {
312 return false;
313 }
314
315 /**
andreaeb70a942015-10-16 21:34:46 -0700316 * Closes the Netconf session with the device.
317 * the first time it tries gracefully, then kills it forcefully
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800318 *
andreaeb70a942015-10-16 21:34:46 -0700319 * @return true if closed
Andrea Campanella101417d2015-12-11 17:58:07 -0800320 * @throws NetconfException when there is a problem in the communication process on
321 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700322 */
Andrea Campanella101417d2015-12-11 17:58:07 -0800323 boolean close() throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700324
325 /**
326 * Gets the session ID of the Netconf session.
327 *
328 * @return Session ID as a string.
329 */
330 String getSessionId();
331
332 /**
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800333 * Gets the capabilities of the remote Netconf device associated to this
334 * session.
335 *
336 * @return Network capabilities as strings in a Set.
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800337 * @since 1.10.0
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800338 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700339 Set<String> getDeviceCapabilitiesSet();
andreaeb70a942015-10-16 21:34:46 -0700340
Andrea Campanella101417d2015-12-11 17:58:07 -0800341 /**
Andrea Campanellac3627842017-04-04 18:06:54 +0200342 * Checks the state of the underlying SSH session and connection
343 * and if necessary it reestablishes it.
344 * Should be implemented, providing a default here for retrocompatibility.
345 * @throws NetconfException when there is a problem in reestablishing
346 * the connection or the session to the device.
347 */
Andrea Campanellac3627842017-04-04 18:06:54 +0200348 default void checkAndReestablish() throws NetconfException {
349 Logger log = LoggerFactory.getLogger(NetconfSession.class);
350 log.error("Not implemented/exposed by the underlying session implementation");
351 }
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700352
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800353 /**
354 * Sets the ONOS side capabilities.
355 *
356 * @param capabilities list of capabilities ONOS has.
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800357 * @since 1.10.0
358 */
359 default void setOnosCapabilities(Iterable<String> capabilities) {
360 // default implementation should be removed in the future
361 // no-op
362 }
Andrea Campanellac3627842017-04-04 18:06:54 +0200363
364 /**
Yuta HIGUCHI4f55c672018-06-14 18:10:43 -0700365 * Add a listener to the underlying stream handler implementation.
Andrea Campanella101417d2015-12-11 17:58:07 -0800366 *
367 * @param listener event listener.
gyewan.an91d7e7e2019-01-17 15:12:48 +0900368 * @throws NetconfException when this method will be called by STANDBY or NONE node.
Andrea Campanella101417d2015-12-11 17:58:07 -0800369 */
gyewan.an91d7e7e2019-01-17 15:12:48 +0900370 void addDeviceOutputListener(NetconfDeviceOutputEventListener listener) throws NetconfException;
Andrea Campanella101417d2015-12-11 17:58:07 -0800371
372 /**
373 * Remove a listener from the underlying stream handler implementation.
374 *
375 * @param listener event listener.
gyewan.an91d7e7e2019-01-17 15:12:48 +0900376 * @throws NetconfException when this method will be called by STANDBY or NONE node.
Andrea Campanella101417d2015-12-11 17:58:07 -0800377 */
gyewan.an91d7e7e2019-01-17 15:12:48 +0900378 void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener) throws NetconfException;
Andrea Campanella101417d2015-12-11 17:58:07 -0800379
Sean Condon54d82432017-07-26 22:27:25 +0100380 /**
381 * Read the connect timeout that this session was created with.
382 * @return timeout in seconds
383 */
384 default int timeoutConnectSec() {
385 return 0;
Yuta HIGUCHI4f55c672018-06-14 18:10:43 -0700386 }
Sean Condon54d82432017-07-26 22:27:25 +0100387
388 /**
389 * Read the reply timeout that this session was created with.
390 * @return timeout in seconds
391 */
392 default int timeoutReplySec() {
393 return 0;
Yuta HIGUCHI4f55c672018-06-14 18:10:43 -0700394 }
Sean Condon54d82432017-07-26 22:27:25 +0100395
396 /**
397 * Read the idle timeout that this session was created with.
398 * @return timeout in seconds
399 */
400 default int timeoutIdleSec() {
401 return 0;
Yuta HIGUCHI4f55c672018-06-14 18:10:43 -0700402 }
Sean Condon54d82432017-07-26 22:27:25 +0100403
andreaeb70a942015-10-16 21:34:46 -0700404}