blob: a38b6dfbb736e65bde2b0cf68cd7200bf7ce0533 [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 */
58 default CompletableFuture<String> rpc(String request) throws NetconfException {
59 return request(request);
60 }
61
Andrea Campanella101417d2015-12-11 17:58:07 -080062
63 /**
Sean Condond2c8d472017-02-17 17:09:39 +000064 * Retrieves the requested configuration, different from get-config.
Andrea Campanellaf4fd0352015-12-14 17:03:05 -080065 *
andreaeb70a942015-10-16 21:34:46 -070066 * @param request the XML containing the request to the server.
67 * @return device running configuration
Andrea Campanella101417d2015-12-11 17:58:07 -080068 * @throws NetconfException when there is a problem in the communication process on
69 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -070070 */
Andrea Campanella101417d2015-12-11 17:58:07 -080071 String get(String request) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -070072
73 /**
Sean Condond2c8d472017-02-17 17:09:39 +000074 * Retrieves the requested data.
Akihiro Yamanouchi5e5d4df2016-06-08 17:06:33 +090075 *
76 * @param filterSchema XML subtrees to include in the reply
77 * @param withDefaultsMode with-defaults mode
78 * @return Server response
79 * @throws NetconfException when there is a problem in the communication process on
80 * the underlying connection
81 */
82 String get(String filterSchema, String withDefaultsMode)
83 throws NetconfException;
84
85 /**
Akihiro Yamanouchi45122222016-07-15 13:13:11 +090086 * Executes an synchronous RPC to the server and wrap the request in RPC header.
Akihiro Yamanouchi8d3a9d32016-07-12 11:41:44 +090087 *
88 * @param request the XML containing the request to the server.
89 * @return Server response or ERROR
90 * @throws NetconfException when there is a problem in the communication process on
91 * the underlying connection
92 */
93 String doWrappedRpc(String request) throws NetconfException;
94
95 /**
Andrea Campanella101417d2015-12-11 17:58:07 -080096 * Executes an synchronous RPC to the server.
Andrea Campanellaf4fd0352015-12-14 17:03:05 -080097 *
andreaeb70a942015-10-16 21:34:46 -070098 * @param request the XML containing the RPC for the server.
99 * @return Server response or ERROR
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 */
Andrea Campanella101417d2015-12-11 17:58:07 -0800103 String requestSync(String request) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700104
105 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700106 * Retrieves the specified configuration.
andreaeb70a942015-10-16 21:34:46 -0700107 *
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300108 * @param netconfTargetConfig the type of configuration to retrieve.
andreaeb70a942015-10-16 21:34:46 -0700109 * @return specified configuration.
Andrea Campanella101417d2015-12-11 17:58:07 -0800110 * @throws NetconfException when there is a problem in the communication process on
111 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700112 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700113 String getConfig(DatastoreId netconfTargetConfig) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700114
115 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700116 * Retrieves part of the specified configuration based on the filterSchema.
117 *
118 * @param netconfTargetConfig the type of configuration to retrieve.
119 * @param configurationFilterSchema XML schema to filter the configuration
120 * elements we are interested in
121 * @return device running configuration.
122 * @throws NetconfException when there is a problem in the communication process on
123 * the underlying connection
124 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700125 String getConfig(DatastoreId netconfTargetConfig,
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700126 String configurationFilterSchema)
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700127 throws NetconfException;
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300128
andreaeb70a942015-10-16 21:34:46 -0700129 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700130 * Retrieves part of the specified configuration based on the filterSchema.
andreaeb70a942015-10-16 21:34:46 -0700131 *
132 * @param newConfiguration configuration to set
133 * @return true if the configuration was edited correctly
Andrea Campanella101417d2015-12-11 17:58:07 -0800134 * @throws NetconfException when there is a problem in the communication process on
135 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700136 */
Andrea Campanella101417d2015-12-11 17:58:07 -0800137 boolean editConfig(String newConfiguration) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700138
139 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700140 * Retrieves part of the specified configuration based on the filterSchema.
141 *
142 * @param netconfTargetConfig the targetConfiguration to change
Yuta HIGUCHIe34c9c22017-12-04 17:47:14 -0800143 * @param mode default-operation mode
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700144 * @param newConfiguration configuration to set
145 * @return true if the configuration was edited correctly
146 * @throws NetconfException when there is a problem in the communication process on
147 * the underlying connection
148 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700149 boolean editConfig(DatastoreId netconfTargetConfig, String mode, String newConfiguration)
150 throws NetconfException;
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700151
152 /**
153 * Copies the configuration between configuration datastores.
154 * <p>
155 * The target configuration can't be the running one
156 *
157 * @param destination configuration datastore
158 * @param source configuration datastore
159 * @return true if the configuration was copied correctly
160 * @throws NetconfException when there is a problem in the communication process on
161 * the underlying connection
162 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700163 boolean copyConfig(DatastoreId destination, DatastoreId source)
164 throws NetconfException;
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700165
166 /**
167 * Copies the new configuration, an Url or a complete configuration xml tree
168 * to the target configuration.
169 * The target configuration can't be the running one
170 *
171 * @param netconfTargetConfig the type of configuration to retrieve.
172 * @param newConfiguration configuration XML to set or URL tag to the configuration
173 * @return true if the configuration was copied correctly
174 * @throws NetconfException when there is a problem in the communication process on
175 * the underlying connection
176 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700177 boolean copyConfig(DatastoreId netconfTargetConfig, String newConfiguration)
178 throws NetconfException;
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800179
180 /**
andreaeb70a942015-10-16 21:34:46 -0700181 * Copies the new configuration, an Url or a complete configuration xml tree
182 * to the target configuration.
183 * The target configuration can't be the running one
184 *
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300185 * @param netconfTargetConfig the type of configuration to retrieve.
186 * @param newConfiguration configuration to set
187 * @return true if the configuration was copied correctly
188 * @throws NetconfException when there is a problem in the communication process on
189 * the underlying connection
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300190 */
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300191 boolean copyConfig(String netconfTargetConfig, String newConfiguration)
192 throws NetconfException;
193
194 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700195 * Deletes part of the specified configuration based on the filterSchema.
196 *
197 * @param netconfTargetConfig the name of the configuration to delete
198 * @return true if the configuration was copied correctly
199 * @throws NetconfException when there is a problem in the communication process on
200 * the underlying connection
201 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700202 boolean deleteConfig(DatastoreId netconfTargetConfig) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700203
204 /**
helenyrwu0407c642016-06-09 12:01:30 -0700205 * Starts subscription to the device's notifications.
206 *
207 * @throws NetconfException when there is a problem starting the subscription
208 */
209 void startSubscription() throws NetconfException;
210
211 /**
Akihiro Yamanouchi45122222016-07-15 13:13:11 +0900212 * Starts subscription to the device's notifications.
213 *
214 * @param filterSchema XML subtrees to indicate specific notification
215 * @throws NetconfException when there is a problem starting the subscription
216 */
217 @Beta
218 void startSubscription(String filterSchema) throws NetconfException;
219
220 /**
helenyrwu0407c642016-06-09 12:01:30 -0700221 * Ends subscription to the device's notifications.
222 *
223 * @throws NetconfException when there is a problem ending the subscription
224 */
225 void endSubscription() throws NetconfException;
226
227 /**
228 * Locks the specified configuration.
229 *
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700230 * @param datastore configuration datastore to be locked
helenyrwu0407c642016-06-09 12:01:30 -0700231 * @return true if successful.
232 * @throws NetconfException when there is a problem in the communication process on
233 * the underlying connection
234 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700235 boolean lock(DatastoreId datastore) throws NetconfException;
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700236
237 /**
238 * Unlocks the specified configuration.
239 *
240 * @param datastore configuration datastore to be unlocked
241 * @return true if successful.
242 * @throws NetconfException when there is a problem in the communication process on
243 * the underlying connection
244 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700245 boolean unlock(DatastoreId datastore) throws NetconfException;
helenyrwu0407c642016-06-09 12:01:30 -0700246
247 /**
248 * Locks the running configuration.
andreaeb70a942015-10-16 21:34:46 -0700249 *
250 * @return true if successful.
Andrea Campanella101417d2015-12-11 17:58:07 -0800251 * @throws NetconfException when there is a problem in the communication process on
252 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700253 */
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700254 default boolean lock() throws NetconfException {
255 return lock(DatastoreId.RUNNING);
256 }
andreaeb70a942015-10-16 21:34:46 -0700257
258 /**
helenyrwu0407c642016-06-09 12:01:30 -0700259 * Unlocks the running configuration.
andreaeb70a942015-10-16 21:34:46 -0700260 *
261 * @return true if successful.
Andrea Campanella101417d2015-12-11 17:58:07 -0800262 * @throws NetconfException when there is a problem in the communication process on
263 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700264 */
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700265 default boolean unlock() throws NetconfException {
266 return unlock(DatastoreId.RUNNING);
267 }
andreaeb70a942015-10-16 21:34:46 -0700268
269 /**
270 * Closes the Netconf session with the device.
271 * the first time it tries gracefully, then kills it forcefully
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800272 *
andreaeb70a942015-10-16 21:34:46 -0700273 * @return true if closed
Andrea Campanella101417d2015-12-11 17:58:07 -0800274 * @throws NetconfException when there is a problem in the communication process on
275 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700276 */
Andrea Campanella101417d2015-12-11 17:58:07 -0800277 boolean close() throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700278
279 /**
280 * Gets the session ID of the Netconf session.
281 *
282 * @return Session ID as a string.
283 */
284 String getSessionId();
285
286 /**
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800287 * Gets the capabilities of the remote Netconf device associated to this
288 * session.
289 *
290 * @return Network capabilities as strings in a Set.
291 *
292 * @since 1.10.0
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800293 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700294 Set<String> getDeviceCapabilitiesSet();
andreaeb70a942015-10-16 21:34:46 -0700295
Andrea Campanella101417d2015-12-11 17:58:07 -0800296 /**
Andrea Campanellac3627842017-04-04 18:06:54 +0200297 * Checks the state of the underlying SSH session and connection
298 * and if necessary it reestablishes it.
299 * Should be implemented, providing a default here for retrocompatibility.
300 * @throws NetconfException when there is a problem in reestablishing
301 * the connection or the session to the device.
302 */
Andrea Campanellac3627842017-04-04 18:06:54 +0200303 default void checkAndReestablish() throws NetconfException {
304 Logger log = LoggerFactory.getLogger(NetconfSession.class);
305 log.error("Not implemented/exposed by the underlying session implementation");
306 }
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700307
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800308 /**
309 * Sets the ONOS side capabilities.
310 *
311 * @param capabilities list of capabilities ONOS has.
312 *
313 * @since 1.10.0
314 */
315 default void setOnosCapabilities(Iterable<String> capabilities) {
316 // default implementation should be removed in the future
317 // no-op
318 }
Andrea Campanellac3627842017-04-04 18:06:54 +0200319
320 /**
Andrea Campanella101417d2015-12-11 17:58:07 -0800321 * Remove a listener from the underlying stream handler implementation.
322 *
323 * @param listener event listener.
324 */
325 void addDeviceOutputListener(NetconfDeviceOutputEventListener listener);
326
327 /**
328 * Remove a listener from the underlying stream handler implementation.
329 *
330 * @param listener event listener.
331 */
332 void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener);
333
Sean Condon54d82432017-07-26 22:27:25 +0100334 /**
335 * Read the connect timeout that this session was created with.
336 * @return timeout in seconds
337 */
338 default int timeoutConnectSec() {
339 return 0;
340 };
341
342 /**
343 * Read the reply timeout that this session was created with.
344 * @return timeout in seconds
345 */
346 default int timeoutReplySec() {
347 return 0;
348 };
349
350 /**
351 * Read the idle timeout that this session was created with.
352 * @return timeout in seconds
353 */
354 default int timeoutIdleSec() {
355 return 0;
356 };
357
andreaeb70a942015-10-16 21:34:46 -0700358}