blob: 31481d274d6ac79a009cc7242f43b5228ca94590 [file] [log] [blame]
andreaeb70a942015-10-16 21:34:46 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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
andreaeb70a942015-10-16 21:34:46 -070023import java.util.List;
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 /**
92 * Retrives the specified configuration.
93 *
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 */
Andrei Mihaescuac542ca2017-03-26 21:36:25 +030099 String getConfig(TargetConfig netconfTargetConfig) throws NetconfException;
100
101 /**
102 * Retrives the specified configuration.
103 *
104 * @param netconfTargetConfig the type of configuration to retrieve.
105 * @return specified configuration.
106 * @throws NetconfException when there is a problem in the communication process on
107 * the underlying connection
108 * @deprecated - 1.10.0 Kingfisher use method overload that accepts
109 * org.onosproject.netconf.TargetConfig enum parameter instead
110 */
111 @Deprecated
112 String getConfig(String netconfTargetConfig) throws NetconfException;
113
andreaeb70a942015-10-16 21:34:46 -0700114
115 /**
116 * Retrives part of the specivied configuration based on the filterSchema.
117 *
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300118 * @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 * @deprecated - 1.10.0 Kingfisher use method overload that accepts
125 * org.onosproject.netconf.TargetConfig enum parameter instead
126 */
127 @Deprecated
128 String getConfig(String netconfTargetConfig, String configurationFilterSchema)
129 throws NetconfException;
130
131 /**
132 * Retrives part of the specivied configuration based on the filterSchema.
133 *
134 * @param netconfTargetConfig the type of configuration to retrieve.
andreaeb70a942015-10-16 21:34:46 -0700135 * @param configurationFilterSchema XML schema to filter the configuration
136 * elements we are interested in
137 * @return device running configuration.
Andrea Campanella101417d2015-12-11 17:58:07 -0800138 * @throws NetconfException when there is a problem in the communication process on
139 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700140 */
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300141 String getConfig(TargetConfig netconfTargetConfig, String configurationFilterSchema)
Andrea Campanella101417d2015-12-11 17:58:07 -0800142 throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700143
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300144
andreaeb70a942015-10-16 21:34:46 -0700145 /**
146 * Retrives part of the specified configuration based on the filterSchema.
147 *
148 * @param newConfiguration configuration to set
149 * @return true if the configuration was edited correctly
Andrea Campanella101417d2015-12-11 17:58:07 -0800150 * @throws NetconfException when there is a problem in the communication process on
151 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700152 */
153
Andrea Campanella101417d2015-12-11 17:58:07 -0800154 boolean editConfig(String newConfiguration) throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700155
156 /**
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800157 * Retrives part of the specified configuration based on the filterSchema.
Andrea Campanella101417d2015-12-11 17:58:07 -0800158 *
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300159 * @param netconfTargetConfig the targetConfiguration to change
160 * @param mode selected mode to change the configuration
161 * @param newConfiguration configuration to set
162 * @return true if the configuration was edited correctly
163 * @throws NetconfException when there is a problem in the communication process on
164 * the underlying connection
165 * @deprecated - 1.10.0 Kingfisher use method overload that accepts
166 * org.onosproject.netconf.TargetConfig enum parameter instead
167 */
168 @Deprecated
169 boolean editConfig(String netconfTargetConfig, String mode, String newConfiguration)
170 throws NetconfException;
171
172 /**
173 * Retrives part of the specified configuration based on the filterSchema.
174 *
175 * @param netconfTargetConfig the targetConfiguration to change
Andrea Campanella101417d2015-12-11 17:58:07 -0800176 * @param mode selected mode to change the configuration
177 * @param newConfiguration configuration to set
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800178 * @return true if the configuration was edited correctly
Andrea Campanella101417d2015-12-11 17:58:07 -0800179 * @throws NetconfException when there is a problem in the communication process on
180 * the underlying connection
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800181 */
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300182 boolean editConfig(TargetConfig netconfTargetConfig, String mode, String newConfiguration)
Andrea Campanella101417d2015-12-11 17:58:07 -0800183 throws NetconfException;
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800184
185 /**
andreaeb70a942015-10-16 21:34:46 -0700186 * Copies the new configuration, an Url or a complete configuration xml tree
187 * to the target configuration.
188 * The target configuration can't be the running one
189 *
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300190 * @param netconfTargetConfig the type of configuration to retrieve.
191 * @param newConfiguration configuration to set
192 * @return true if the configuration was copied correctly
193 * @throws NetconfException when there is a problem in the communication process on
194 * the underlying connection
195 * @deprecated - 1.10.0 Kingfisher use method overload that accepts
196 * org.onosproject.netconf.TargetConfig enum parameter instead
197 */
198 @Deprecated
199 boolean copyConfig(String netconfTargetConfig, String newConfiguration)
200 throws NetconfException;
201
202 /**
203 * 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 *
207 * @param netconfTargetConfig the type of configuration to retrieve.
andreaeb70a942015-10-16 21:34:46 -0700208 * @param newConfiguration configuration to set
209 * @return true if the configuration was copied correctly
Andrea Campanella101417d2015-12-11 17:58:07 -0800210 * @throws NetconfException when there is a problem in the communication process on
211 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700212 */
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300213 boolean copyConfig(TargetConfig netconfTargetConfig, String newConfiguration)
Andrea Campanella101417d2015-12-11 17:58:07 -0800214 throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700215
216 /**
217 * Deletes part of the specified configuration based on the filterSchema.
218 *
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300219 * @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 * @deprecated - 1.10.0 Kingfisher use method overload that accepts
224 * org.onosproject.netconf.TargetConfig enum parameter instead
225 */
226 @Deprecated
227 boolean deleteConfig(String netconfTargetConfig) throws NetconfException;
228
229 /**
230 * Deletes part of the specified configuration based on the filterSchema.
231 *
232 * @param netconfTargetConfig the name of the configuration to delete
andreaeb70a942015-10-16 21:34:46 -0700233 * @return true if the configuration was copied correctly
Andrea Campanella101417d2015-12-11 17:58:07 -0800234 * @throws NetconfException when there is a problem in the communication process on
235 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700236 */
Andrei Mihaescuac542ca2017-03-26 21:36:25 +0300237 boolean deleteConfig(TargetConfig 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 *
265 * @param configType type of configuration to be locked
266 * @return true if successful.
267 * @throws NetconfException when there is a problem in the communication process on
268 * the underlying connection
269 */
270 boolean lock(String configType) throws NetconfException;
271
272 /**
273 * Unlocks the specified configuration.
274 *
275 * @param configType type of configuration to be locked
276 * @return true if successful.
277 * @throws NetconfException when there is a problem in the communication process on
278 * the underlying connection
279 */
280 boolean unlock(String configType) throws NetconfException;
281
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 */
Andrea Campanella101417d2015-12-11 17:58:07 -0800289 boolean lock() throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700290
291 /**
helenyrwu0407c642016-06-09 12:01:30 -0700292 * Unlocks the running configuration.
andreaeb70a942015-10-16 21:34:46 -0700293 *
294 * @return true if successful.
Andrea Campanella101417d2015-12-11 17:58:07 -0800295 * @throws NetconfException when there is a problem in the communication process on
296 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700297 */
Andrea Campanella101417d2015-12-11 17:58:07 -0800298 boolean unlock() throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700299
300 /**
301 * Closes the Netconf session with the device.
302 * the first time it tries gracefully, then kills it forcefully
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800303 *
andreaeb70a942015-10-16 21:34:46 -0700304 * @return true if closed
Andrea Campanella101417d2015-12-11 17:58:07 -0800305 * @throws NetconfException when there is a problem in the communication process on
306 * the underlying connection
andreaeb70a942015-10-16 21:34:46 -0700307 */
Andrea Campanella101417d2015-12-11 17:58:07 -0800308 boolean close() throws NetconfException;
andreaeb70a942015-10-16 21:34:46 -0700309
310 /**
311 * Gets the session ID of the Netconf session.
312 *
313 * @return Session ID as a string.
314 */
315 String getSessionId();
316
317 /**
318 * Gets the capabilities of the Netconf server associated to this session.
319 *
320 * @return Network capabilities as a string.
321 */
322 String getServerCapabilities();
323
324 /**
Andrea Campanella101417d2015-12-11 17:58:07 -0800325 * Sets the ONOS side capabilities.
Andrea Campanellaf4fd0352015-12-14 17:03:05 -0800326 *
andreaeb70a942015-10-16 21:34:46 -0700327 * @param capabilities list of capabilities the device has.
328 */
329 void setDeviceCapabilities(List<String> capabilities);
330
Andrea Campanella101417d2015-12-11 17:58:07 -0800331 /**
Andrea Campanellac3627842017-04-04 18:06:54 +0200332 * Checks the state of the underlying SSH session and connection
333 * and if necessary it reestablishes it.
334 * Should be implemented, providing a default here for retrocompatibility.
335 * @throws NetconfException when there is a problem in reestablishing
336 * the connection or the session to the device.
337 */
338
339 default void checkAndReestablish() throws NetconfException {
340 Logger log = LoggerFactory.getLogger(NetconfSession.class);
341 log.error("Not implemented/exposed by the underlying session implementation");
342 }
343
344 /**
Andrea Campanella101417d2015-12-11 17:58:07 -0800345 * Remove a listener from the underlying stream handler implementation.
346 *
347 * @param listener event listener.
348 */
349 void addDeviceOutputListener(NetconfDeviceOutputEventListener listener);
350
351 /**
352 * Remove a listener from the underlying stream handler implementation.
353 *
354 * @param listener event listener.
355 */
356 void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener);
357
andreaeb70a942015-10-16 21:34:46 -0700358}