blob: 420a961c8f3428c570f22a730769ece722b74855 [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
48
49 /**
Sean Condond2c8d472017-02-17 17:09:39 +000050 * Retrieves the requested configuration, different from get-config.
Andrea Campanellaf4fd0352015-12-14 17:03:05 -080051 *
andreaeb70a942015-10-16 21:34:46 -070052 * @param request the XML containing the request to the server.
53 * @return device running configuration
Andrea Campanella101417d2015-12-11 17:58:07 -080054 * @throws NetconfException when there is a problem in the communication process on
55 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -070056 */
Andrea Campanella101417d2015-12-11 17:58:07 -080057 String get(String request) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -070058
59 /**
Sean Condond2c8d472017-02-17 17:09:39 +000060 * Retrieves the requested data.
Akihiro Yamanouchi5e5d4df2016-06-08 17:06:33 +090061 *
62 * @param filterSchema XML subtrees to include in the reply
63 * @param withDefaultsMode with-defaults mode
64 * @return Server response
65 * @throws NetconfException when there is a problem in the communication process on
66 * the underlying connection
67 */
68 String get(String filterSchema, String withDefaultsMode)
69 throws NetconfException;
70
71 /**
Akihiro Yamanouchi45122222016-07-15 13:13:11 +090072 * Executes an synchronous RPC to the server and wrap the request in RPC header.
Akihiro Yamanouchi8d3a9d32016-07-12 11:41:44 +090073 *
74 * @param request the XML containing the request to the server.
75 * @return Server response or ERROR
76 * @throws NetconfException when there is a problem in the communication process on
77 * the underlying connection
78 */
79 String doWrappedRpc(String request) throws NetconfException;
80
81 /**
Andrea Campanella101417d2015-12-11 17:58:07 -080082 * Executes an synchronous RPC to the server.
Andrea Campanellaf4fd0352015-12-14 17:03:05 -080083 *
andreaeb70a942015-10-16 21:34:46 -070084 * @param request the XML containing the RPC for the server.
85 * @return Server response or ERROR
Andrea Campanella101417d2015-12-11 17:58:07 -080086 * @throws NetconfException when there is a problem in the communication process on
87 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -070088 */
Andrea Campanella101417d2015-12-11 17:58:07 -080089 String requestSync(String request) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -070090
91 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -070092 * Retrieves the specified configuration.
andreaeb70a942015-10-16 21:34:46 -070093 *
Andrei Mihaescuac542ca2017-03-26 21:36:25 +030094 * @param netconfTargetConfig the type of configuration to retrieve.
andreaeb70a942015-10-16 21:34:46 -070095 * @return specified configuration.
Andrea Campanella101417d2015-12-11 17:58:07 -080096 * @throws NetconfException when there is a problem in the communication process on
97 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -070098 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -070099 String getConfig(DatastoreId netconfTargetConfig) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700100
101 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700102 * Retrieves part of the specified configuration based on the filterSchema.
103 *
104 * @param netconfTargetConfig the type of configuration to retrieve.
105 * @param configurationFilterSchema XML schema to filter the configuration
106 * elements we are interested in
107 * @return device running configuration.
108 * @throws NetconfException when there is a problem in the communication process on
109 * the underlying connection
110 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700111 String getConfig(DatastoreId netconfTargetConfig,
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700112 String configurationFilterSchema)
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700113 throws NetconfException;
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300114
andreaeb70a942015-10-16 21:34:46 -0700115 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700116 * Retrieves part of the specified configuration based on the filterSchema.
andreaeb70a942015-10-16 21:34:46 -0700117 *
118 * @param newConfiguration configuration to set
119 * @return true if the configuration was edited correctly
Andrea Campanella101417d2015-12-11 17:58:07 -0800120 * @throws NetconfException when there is a problem in the communication process on
121 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700122 */
Andrea Campanella101417d2015-12-11 17:58:07 -0800123 boolean editConfig(String newConfiguration) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700124
125 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700126 * Retrieves part of the specified configuration based on the filterSchema.
127 *
128 * @param netconfTargetConfig the targetConfiguration to change
129 * @param mode selected mode to change the configuration
130 * @param newConfiguration configuration to set
131 * @return true if the configuration was edited correctly
132 * @throws NetconfException when there is a problem in the communication process on
133 * the underlying connection
134 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700135 boolean editConfig(DatastoreId netconfTargetConfig, String mode, String newConfiguration)
136 throws NetconfException;
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700137
138 /**
139 * Copies the configuration between configuration datastores.
140 * <p>
141 * The target configuration can't be the running one
142 *
143 * @param destination configuration datastore
144 * @param source configuration datastore
145 * @return true if the configuration was copied 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 copyConfig(DatastoreId destination, DatastoreId source)
150 throws NetconfException;
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700151
152 /**
153 * Copies the new configuration, an Url or a complete configuration xml tree
154 * to the target configuration.
155 * The target configuration can't be the running one
156 *
157 * @param netconfTargetConfig the type of configuration to retrieve.
158 * @param newConfiguration configuration XML to set or URL tag to the configuration
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 netconfTargetConfig, String newConfiguration)
164 throws NetconfException;
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800165
166 /**
andreaeb70a942015-10-16 21:34:46 -0700167 * 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 *
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300171 * @param netconfTargetConfig the type of configuration to retrieve.
172 * @param newConfiguration configuration to set
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
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300176 */
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300177 boolean copyConfig(String netconfTargetConfig, String newConfiguration)
178 throws NetconfException;
179
180 /**
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700181 * Deletes part of the specified configuration based on the filterSchema.
182 *
183 * @param netconfTargetConfig the name of the configuration to delete
184 * @return true if the configuration was copied correctly
185 * @throws NetconfException when there is a problem in the communication process on
186 * the underlying connection
187 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700188 boolean deleteConfig(DatastoreId netconfTargetConfig) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700189
190 /**
helenyrwu0407c642016-06-09 12:01:30 -0700191 * Starts subscription to the device's notifications.
192 *
193 * @throws NetconfException when there is a problem starting the subscription
194 */
195 void startSubscription() throws NetconfException;
196
197 /**
Akihiro Yamanouchi45122222016-07-15 13:13:11 +0900198 * Starts subscription to the device's notifications.
199 *
200 * @param filterSchema XML subtrees to indicate specific notification
201 * @throws NetconfException when there is a problem starting the subscription
202 */
203 @Beta
204 void startSubscription(String filterSchema) throws NetconfException;
205
206 /**
helenyrwu0407c642016-06-09 12:01:30 -0700207 * Ends subscription to the device's notifications.
208 *
209 * @throws NetconfException when there is a problem ending the subscription
210 */
211 void endSubscription() throws NetconfException;
212
213 /**
214 * Locks the specified configuration.
215 *
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700216 * @param datastore configuration datastore to be locked
helenyrwu0407c642016-06-09 12:01:30 -0700217 * @return true if successful.
218 * @throws NetconfException when there is a problem in the communication process on
219 * the underlying connection
220 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700221 boolean lock(DatastoreId datastore) throws NetconfException;
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700222
223 /**
224 * Unlocks the specified configuration.
225 *
226 * @param datastore configuration datastore to be unlocked
227 * @return true if successful.
228 * @throws NetconfException when there is a problem in the communication process on
229 * the underlying connection
230 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700231 boolean unlock(DatastoreId datastore) throws NetconfException;
helenyrwu0407c642016-06-09 12:01:30 -0700232
233 /**
234 * Locks the running configuration.
andreaeb70a942015-10-16 21:34:46 -0700235 *
236 * @return true if successful.
Andrea Campanella101417d2015-12-11 17:58:07 -0800237 * @throws NetconfException when there is a problem in the communication process on
238 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700239 */
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700240 default boolean lock() throws NetconfException {
241 return lock(DatastoreId.RUNNING);
242 }
andreaeb70a942015-10-16 21:34:46 -0700243
244 /**
helenyrwu0407c642016-06-09 12:01:30 -0700245 * Unlocks the running configuration.
andreaeb70a942015-10-16 21:34:46 -0700246 *
247 * @return true if successful.
Andrea Campanella101417d2015-12-11 17:58:07 -0800248 * @throws NetconfException when there is a problem in the communication process on
249 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700250 */
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700251 default boolean unlock() throws NetconfException {
252 return unlock(DatastoreId.RUNNING);
253 }
andreaeb70a942015-10-16 21:34:46 -0700254
255 /**
256 * Closes the Netconf session with the device.
257 * the first time it tries gracefully, then kills it forcefully
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800258 *
andreaeb70a942015-10-16 21:34:46 -0700259 * @return true if closed
Andrea Campanella101417d2015-12-11 17:58:07 -0800260 * @throws NetconfException when there is a problem in the communication process on
261 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700262 */
Andrea Campanella101417d2015-12-11 17:58:07 -0800263 boolean close() throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700264
265 /**
266 * Gets the session ID of the Netconf session.
267 *
268 * @return Session ID as a string.
269 */
270 String getSessionId();
271
272 /**
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800273 * Gets the capabilities of the remote Netconf device associated to this
274 * session.
275 *
276 * @return Network capabilities as strings in a Set.
277 *
278 * @since 1.10.0
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800279 */
Yuta HIGUCHIdd7c3f82017-09-03 14:18:01 -0700280 Set<String> getDeviceCapabilitiesSet();
andreaeb70a942015-10-16 21:34:46 -0700281
Andrea Campanella101417d2015-12-11 17:58:07 -0800282 /**
Andrea Campanellac3627842017-04-04 18:06:54 +0200283 * Checks the state of the underlying SSH session and connection
284 * and if necessary it reestablishes it.
285 * Should be implemented, providing a default here for retrocompatibility.
286 * @throws NetconfException when there is a problem in reestablishing
287 * the connection or the session to the device.
288 */
289
290 default void checkAndReestablish() throws NetconfException {
291 Logger log = LoggerFactory.getLogger(NetconfSession.class);
292 log.error("Not implemented/exposed by the underlying session implementation");
293 }
Yuta HIGUCHI89111d92017-05-04 11:29:17 -0700294
Aaron Kruglikov72db6422017-02-13 12:16:51 -0800295 /**
296 * Sets the ONOS side capabilities.
297 *
298 * @param capabilities list of capabilities ONOS has.
299 *
300 * @since 1.10.0
301 */
302 default void setOnosCapabilities(Iterable<String> capabilities) {
303 // default implementation should be removed in the future
304 // no-op
305 }
Andrea Campanellac3627842017-04-04 18:06:54 +0200306
307 /**
Andrea Campanella101417d2015-12-11 17:58:07 -0800308 * Remove a listener from the underlying stream handler implementation.
309 *
310 * @param listener event listener.
311 */
312 void addDeviceOutputListener(NetconfDeviceOutputEventListener listener);
313
314 /**
315 * Remove a listener from the underlying stream handler implementation.
316 *
317 * @param listener event listener.
318 */
319 void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener);
320
Sean Condon54d82432017-07-26 22:27:25 +0100321 /**
322 * Read the connect timeout that this session was created with.
323 * @return timeout in seconds
324 */
325 default int timeoutConnectSec() {
326 return 0;
327 };
328
329 /**
330 * Read the reply timeout that this session was created with.
331 * @return timeout in seconds
332 */
333 default int timeoutReplySec() {
334 return 0;
335 };
336
337 /**
338 * Read the idle timeout that this session was created with.
339 * @return timeout in seconds
340 */
341 default int timeoutIdleSec() {
342 return 0;
343 };
344
andreaeb70a942015-10-16 21:34:46 -0700345}