blob: bc04118bf602330cb1679e63b043e73cb98e7c07 [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 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700125 * Retrieves the specified configuration.
andreaeb70a942015-10-16 21:34:46 -0700126 *
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300127 * @param netconfTargetConfig the type of configuration to retrieve.
andreaeb70a942015-10-16 21:34:46 -0700128 * @return specified configuration.
Andrea Campanella101417d2015-12-11 17:58:07 -0800129 * @throws NetconfException when there is a problem in the communication process on
130 * the underlying connection
Yuta HIGUCHI5ac34432018-02-13 16:29:15 -0800131 *
132 * @deprecated in 1.13.0 use async version instead.
andreaeb70a942015-10-16 21:34:46 -0700133 */
Yuta HIGUCHI5ac34432018-02-13 16:29:15 -0800134 @Deprecated
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700135 String getConfig(DatastoreId netconfTargetConfig) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700136
137 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700138 * Retrieves part of the specified configuration based on the filterSchema.
139 *
140 * @param netconfTargetConfig the type of configuration to retrieve.
141 * @param configurationFilterSchema XML schema to filter the configuration
142 * elements we are interested in
143 * @return device running configuration.
144 * @throws NetconfException when there is a problem in the communication process on
145 * the underlying connection
146 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700147 String getConfig(DatastoreId netconfTargetConfig,
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700148 String configurationFilterSchema)
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700149 throws NetconfException;
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300150
andreaeb70a942015-10-16 21:34:46 -0700151 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700152 * Retrieves part of the specified configuration based on the filterSchema.
andreaeb70a942015-10-16 21:34:46 -0700153 *
154 * @param newConfiguration configuration to set
155 * @return true if the configuration was edited correctly
Andrea Campanella101417d2015-12-11 17:58:07 -0800156 * @throws NetconfException when there is a problem in the communication process on
157 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700158 */
Andrea Campanella101417d2015-12-11 17:58:07 -0800159 boolean editConfig(String newConfiguration) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700160
161 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700162 * Retrieves part of the specified configuration based on the filterSchema.
163 *
164 * @param netconfTargetConfig the targetConfiguration to change
Yuta HIGUCHIe34c9c22017-12-04 17:47:14 -0800165 * @param mode default-operation mode
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700166 * @param newConfiguration configuration to set
167 * @return true if the configuration was edited correctly
168 * @throws NetconfException when there is a problem in the communication process on
169 * the underlying connection
170 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700171 boolean editConfig(DatastoreId netconfTargetConfig, String mode, String newConfiguration)
172 throws NetconfException;
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700173
174 /**
175 * Copies the configuration between configuration datastores.
176 * <p>
177 * The target configuration can't be the running one
178 *
179 * @param destination configuration datastore
180 * @param source configuration datastore
181 * @return true if the configuration was copied correctly
182 * @throws NetconfException when there is a problem in the communication process on
183 * the underlying connection
184 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700185 boolean copyConfig(DatastoreId destination, DatastoreId source)
186 throws NetconfException;
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700187
188 /**
189 * Copies the new configuration, an Url or a complete configuration xml tree
190 * to the target configuration.
191 * The target configuration can't be the running one
192 *
193 * @param netconfTargetConfig the type of configuration to retrieve.
194 * @param newConfiguration configuration XML to set or URL tag to the configuration
195 * @return true if the configuration was copied correctly
196 * @throws NetconfException when there is a problem in the communication process on
197 * the underlying connection
198 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700199 boolean copyConfig(DatastoreId netconfTargetConfig, String newConfiguration)
200 throws NetconfException;
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800201
202 /**
andreaeb70a942015-10-16 21:34:46 -0700203 * Copies the new configuration, an Url or a complete configuration xml tree
204 * to the target configuration.
205 * The target configuration can't be the running one
206 *
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300207 * @param netconfTargetConfig the type of configuration to retrieve.
208 * @param newConfiguration configuration to set
209 * @return true if the configuration was copied correctly
210 * @throws NetconfException when there is a problem in the communication process on
211 * the underlying connection
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300212 */
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300213 boolean copyConfig(String netconfTargetConfig, String newConfiguration)
214 throws NetconfException;
215
216 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700217 * Deletes part of the specified configuration based on the filterSchema.
218 *
219 * @param netconfTargetConfig the name of the configuration to delete
220 * @return true if the configuration was copied correctly
221 * @throws NetconfException when there is a problem in the communication process on
222 * the underlying connection
223 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700224 boolean deleteConfig(DatastoreId netconfTargetConfig) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700225
226 /**
helenyrwu0407c642016-06-09 12:01:30 -0700227 * Starts subscription to the device's notifications.
228 *
229 * @throws NetconfException when there is a problem starting the subscription
230 */
231 void startSubscription() throws NetconfException;
232
233 /**
Akihiro Yamanouchi45122222016-07-15 13:13:11 +0900234 * Starts subscription to the device's notifications.
235 *
236 * @param filterSchema XML subtrees to indicate specific notification
237 * @throws NetconfException when there is a problem starting the subscription
238 */
239 @Beta
240 void startSubscription(String filterSchema) throws NetconfException;
241
242 /**
helenyrwu0407c642016-06-09 12:01:30 -0700243 * Ends subscription to the device's notifications.
244 *
245 * @throws NetconfException when there is a problem ending the subscription
246 */
247 void endSubscription() throws NetconfException;
248
249 /**
250 * Locks the specified configuration.
251 *
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700252 * @param datastore configuration datastore to be locked
helenyrwu0407c642016-06-09 12:01:30 -0700253 * @return true if successful.
254 * @throws NetconfException when there is a problem in the communication process on
255 * the underlying connection
256 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700257 boolean lock(DatastoreId datastore) throws NetconfException;
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700258
259 /**
260 * Unlocks the specified configuration.
261 *
262 * @param datastore configuration datastore to be unlocked
263 * @return true if successful.
264 * @throws NetconfException when there is a problem in the communication process on
265 * the underlying connection
266 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700267 boolean unlock(DatastoreId datastore) throws NetconfException;
helenyrwu0407c642016-06-09 12:01:30 -0700268
269 /**
270 * Locks the running configuration.
andreaeb70a942015-10-16 21:34:46 -0700271 *
272 * @return true if successful.
Andrea Campanella101417d2015-12-11 17:58:07 -0800273 * @throws NetconfException when there is a problem in the communication process on
274 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700275 */
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700276 default boolean lock() throws NetconfException {
277 return lock(DatastoreId.RUNNING);
278 }
andreaeb70a942015-10-16 21:34:46 -0700279
280 /**
helenyrwu0407c642016-06-09 12:01:30 -0700281 * Unlocks the running configuration.
andreaeb70a942015-10-16 21:34:46 -0700282 *
283 * @return true if successful.
Andrea Campanella101417d2015-12-11 17:58:07 -0800284 * @throws NetconfException when there is a problem in the communication process on
285 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700286 */
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700287 default boolean unlock() throws NetconfException {
288 return unlock(DatastoreId.RUNNING);
289 }
andreaeb70a942015-10-16 21:34:46 -0700290
291 /**
292 * Closes the Netconf session with the device.
293 * the first time it tries gracefully, then kills it forcefully
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800294 *
andreaeb70a942015-10-16 21:34:46 -0700295 * @return true if closed
Andrea Campanella101417d2015-12-11 17:58:07 -0800296 * @throws NetconfException when there is a problem in the communication process on
297 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700298 */
Andrea Campanella101417d2015-12-11 17:58:07 -0800299 boolean close() throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700300
301 /**
302 * Gets the session ID of the Netconf session.
303 *
304 * @return Session ID as a string.
305 */
306 String getSessionId();
307
308 /**
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800309 * Gets the capabilities of the remote Netconf device associated to this
310 * session.
311 *
312 * @return Network capabilities as strings in a Set.
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800313 * @since 1.10.0
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800314 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700315 Set<String> getDeviceCapabilitiesSet();
andreaeb70a942015-10-16 21:34:46 -0700316
Andrea Campanella101417d2015-12-11 17:58:07 -0800317 /**
Andrea Campanellac3627842017-04-04 18:06:54 +0200318 * Checks the state of the underlying SSH session and connection
319 * and if necessary it reestablishes it.
320 * Should be implemented, providing a default here for retrocompatibility.
321 * @throws NetconfException when there is a problem in reestablishing
322 * the connection or the session to the device.
323 */
Andrea Campanellac3627842017-04-04 18:06:54 +0200324 default void checkAndReestablish() throws NetconfException {
325 Logger log = LoggerFactory.getLogger(NetconfSession.class);
326 log.error("Not implemented/exposed by the underlying session implementation");
327 }
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700328
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800329 /**
330 * Sets the ONOS side capabilities.
331 *
332 * @param capabilities list of capabilities ONOS has.
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800333 * @since 1.10.0
334 */
335 default void setOnosCapabilities(Iterable<String> capabilities) {
336 // default implementation should be removed in the future
337 // no-op
338 }
Andrea Campanellac3627842017-04-04 18:06:54 +0200339
340 /**
Yuta HIGUCHI4f55c672018-06-14 18:10:43 -0700341 * Add a listener to the underlying stream handler implementation.
Andrea Campanella101417d2015-12-11 17:58:07 -0800342 *
343 * @param listener event listener.
344 */
345 void addDeviceOutputListener(NetconfDeviceOutputEventListener listener);
346
347 /**
348 * Remove a listener from the underlying stream handler implementation.
349 *
350 * @param listener event listener.
351 */
352 void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener);
353
Sean Condon54d82432017-07-26 22:27:25 +0100354 /**
355 * Read the connect timeout that this session was created with.
356 * @return timeout in seconds
357 */
358 default int timeoutConnectSec() {
359 return 0;
Yuta HIGUCHI4f55c672018-06-14 18:10:43 -0700360 }
Sean Condon54d82432017-07-26 22:27:25 +0100361
362 /**
363 * Read the reply timeout that this session was created with.
364 * @return timeout in seconds
365 */
366 default int timeoutReplySec() {
367 return 0;
Yuta HIGUCHI4f55c672018-06-14 18:10:43 -0700368 }
Sean Condon54d82432017-07-26 22:27:25 +0100369
370 /**
371 * Read the idle timeout that this session was created with.
372 * @return timeout in seconds
373 */
374 default int timeoutIdleSec() {
375 return 0;
Yuta HIGUCHI4f55c672018-06-14 18:10:43 -0700376 }
Sean Condon54d82432017-07-26 22:27:25 +0100377
andreaeb70a942015-10-16 21:34:46 -0700378}