andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | package org.onosproject.netconf; |
| 18 | |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 19 | import com.google.common.annotations.Beta; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 20 | import java.util.List; |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 21 | import java.util.concurrent.CompletableFuture; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * NETCONF session object that allows NETCONF operations on top with the physical |
| 25 | * device on top of an SSH connection. |
| 26 | */ |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame^] | 27 | // TODO change return type of methods to <Capability, XMLdoc, string or yang obj> |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 28 | public interface NetconfSession { |
| 29 | |
| 30 | /** |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 31 | * Executes an asynchronous RPC to the server and obtains a future to be completed. |
| 32 | * |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame^] | 33 | * The caller must ensure that the message-id in any request is unique |
| 34 | * for the session |
| 35 | * |
| 36 | * @deprecated - 1.10.0 do not remove needs reworking |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 37 | * @param request the XML containing the RPC for the server. |
| 38 | * @return Server response or ERROR |
| 39 | * @throws NetconfException when there is a problem in the communication process on |
| 40 | * the underlying connection |
| 41 | */ |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame^] | 42 | @Deprecated |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 43 | CompletableFuture<String> request(String request) throws NetconfException; |
| 44 | |
| 45 | |
| 46 | /** |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame^] | 47 | * Retrieves the requested configuration, different from get-config. |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 48 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 49 | * @param request the XML containing the request to the server. |
| 50 | * @return device running configuration |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 51 | * @throws NetconfException when there is a problem in the communication process on |
| 52 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 53 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 54 | String get(String request) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 55 | |
| 56 | /** |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame^] | 57 | * Retrieves the requested data. |
Akihiro Yamanouchi | 5e5d4df | 2016-06-08 17:06:33 +0900 | [diff] [blame] | 58 | * |
| 59 | * @param filterSchema XML subtrees to include in the reply |
| 60 | * @param withDefaultsMode with-defaults mode |
| 61 | * @return Server response |
| 62 | * @throws NetconfException when there is a problem in the communication process on |
| 63 | * the underlying connection |
| 64 | */ |
| 65 | String get(String filterSchema, String withDefaultsMode) |
| 66 | throws NetconfException; |
| 67 | |
| 68 | /** |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 69 | * Executes an synchronous RPC to the server and wrap the request in RPC header. |
Akihiro Yamanouchi | 8d3a9d3 | 2016-07-12 11:41:44 +0900 | [diff] [blame] | 70 | * |
| 71 | * @param request the XML containing the request to the server. |
| 72 | * @return Server response or ERROR |
| 73 | * @throws NetconfException when there is a problem in the communication process on |
| 74 | * the underlying connection |
| 75 | */ |
| 76 | String doWrappedRpc(String request) throws NetconfException; |
| 77 | |
| 78 | /** |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 79 | * Executes an synchronous RPC to the server. |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 80 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 81 | * @param request the XML containing the RPC for the server. |
| 82 | * @return Server response or ERROR |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 83 | * @throws NetconfException when there is a problem in the communication process on |
| 84 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 85 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 86 | String requestSync(String request) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * Retrives the specified configuration. |
| 90 | * |
| 91 | * @param targetConfiguration the type of configuration to retrieve. |
| 92 | * @return specified configuration. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 93 | * @throws NetconfException when there is a problem in the communication process on |
| 94 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 95 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 96 | String getConfig(String targetConfiguration) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * Retrives part of the specivied configuration based on the filterSchema. |
| 100 | * |
| 101 | * @param targetConfiguration the type of configuration to retrieve. |
| 102 | * @param configurationFilterSchema XML schema to filter the configuration |
| 103 | * elements we are interested in |
| 104 | * @return device running configuration. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 105 | * @throws NetconfException when there is a problem in the communication process on |
| 106 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 107 | */ |
Andrea Campanella | 1cd641b | 2015-12-07 17:28:34 -0800 | [diff] [blame] | 108 | String getConfig(String targetConfiguration, String configurationFilterSchema) |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 109 | throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 110 | |
| 111 | /** |
| 112 | * Retrives part of the specified configuration based on the filterSchema. |
| 113 | * |
| 114 | * @param newConfiguration configuration to set |
| 115 | * @return true if the configuration was edited correctly |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 116 | * @throws NetconfException when there is a problem in the communication process on |
| 117 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 118 | */ |
| 119 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 120 | boolean editConfig(String newConfiguration) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 121 | |
| 122 | /** |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 123 | * Retrives part of the specified configuration based on the filterSchema. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 124 | * |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 125 | * @param targetConfiguration the targetConfiguration to change |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 126 | * @param mode selected mode to change the configuration |
| 127 | * @param newConfiguration configuration to set |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 128 | * @return true if the configuration was edited correctly |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 129 | * @throws NetconfException when there is a problem in the communication process on |
| 130 | * the underlying connection |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 131 | */ |
| 132 | boolean editConfig(String targetConfiguration, String mode, String newConfiguration) |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 133 | throws NetconfException; |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 134 | |
| 135 | /** |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 136 | * Copies the new configuration, an Url or a complete configuration xml tree |
| 137 | * to the target configuration. |
| 138 | * The target configuration can't be the running one |
| 139 | * |
| 140 | * @param targetConfiguration the type of configuration to retrieve. |
| 141 | * @param newConfiguration configuration to set |
| 142 | * @return true if the configuration was copied correctly |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 143 | * @throws NetconfException when there is a problem in the communication process on |
| 144 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 145 | */ |
Andrea Campanella | 1cd641b | 2015-12-07 17:28:34 -0800 | [diff] [blame] | 146 | boolean copyConfig(String targetConfiguration, String newConfiguration) |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 147 | throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * Deletes part of the specified configuration based on the filterSchema. |
| 151 | * |
| 152 | * @param targetConfiguration the name of the configuration to delete |
| 153 | * @return true if the configuration was copied correctly |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 154 | * @throws NetconfException when there is a problem in the communication process on |
| 155 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 156 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 157 | boolean deleteConfig(String targetConfiguration) throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 158 | |
| 159 | /** |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 160 | * Starts subscription to the device's notifications. |
| 161 | * |
| 162 | * @throws NetconfException when there is a problem starting the subscription |
| 163 | */ |
| 164 | void startSubscription() throws NetconfException; |
| 165 | |
| 166 | /** |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 167 | * Starts subscription to the device's notifications. |
| 168 | * |
| 169 | * @param filterSchema XML subtrees to indicate specific notification |
| 170 | * @throws NetconfException when there is a problem starting the subscription |
| 171 | */ |
| 172 | @Beta |
| 173 | void startSubscription(String filterSchema) throws NetconfException; |
| 174 | |
| 175 | /** |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 176 | * Ends subscription to the device's notifications. |
| 177 | * |
| 178 | * @throws NetconfException when there is a problem ending the subscription |
| 179 | */ |
| 180 | void endSubscription() throws NetconfException; |
| 181 | |
| 182 | /** |
| 183 | * Locks the specified configuration. |
| 184 | * |
| 185 | * @param configType type of configuration to be locked |
| 186 | * @return true if successful. |
| 187 | * @throws NetconfException when there is a problem in the communication process on |
| 188 | * the underlying connection |
| 189 | */ |
| 190 | boolean lock(String configType) throws NetconfException; |
| 191 | |
| 192 | /** |
| 193 | * Unlocks the specified configuration. |
| 194 | * |
| 195 | * @param configType type of configuration to be locked |
| 196 | * @return true if successful. |
| 197 | * @throws NetconfException when there is a problem in the communication process on |
| 198 | * the underlying connection |
| 199 | */ |
| 200 | boolean unlock(String configType) throws NetconfException; |
| 201 | |
| 202 | /** |
| 203 | * Locks the running configuration. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 204 | * |
| 205 | * @return true if successful. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 206 | * @throws NetconfException when there is a problem in the communication process on |
| 207 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 208 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 209 | boolean lock() throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 210 | |
| 211 | /** |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 212 | * Unlocks the running configuration. |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 213 | * |
| 214 | * @return true if successful. |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 215 | * @throws NetconfException when there is a problem in the communication process on |
| 216 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 217 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 218 | boolean unlock() throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 219 | |
| 220 | /** |
| 221 | * Closes the Netconf session with the device. |
| 222 | * the first time it tries gracefully, then kills it forcefully |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 223 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 224 | * @return true if closed |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 225 | * @throws NetconfException when there is a problem in the communication process on |
| 226 | * the underlying connection |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 227 | */ |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 228 | boolean close() throws NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 229 | |
| 230 | /** |
| 231 | * Gets the session ID of the Netconf session. |
| 232 | * |
| 233 | * @return Session ID as a string. |
| 234 | */ |
| 235 | String getSessionId(); |
| 236 | |
| 237 | /** |
| 238 | * Gets the capabilities of the Netconf server associated to this session. |
| 239 | * |
| 240 | * @return Network capabilities as a string. |
| 241 | */ |
| 242 | String getServerCapabilities(); |
| 243 | |
| 244 | /** |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 245 | * Sets the ONOS side capabilities. |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 246 | * |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 247 | * @param capabilities list of capabilities the device has. |
| 248 | */ |
| 249 | void setDeviceCapabilities(List<String> capabilities); |
| 250 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 251 | /** |
| 252 | * Remove a listener from the underlying stream handler implementation. |
| 253 | * |
| 254 | * @param listener event listener. |
| 255 | */ |
| 256 | void addDeviceOutputListener(NetconfDeviceOutputEventListener listener); |
| 257 | |
| 258 | /** |
| 259 | * Remove a listener from the underlying stream handler implementation. |
| 260 | * |
| 261 | * @param listener event listener. |
| 262 | */ |
| 263 | void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener); |
| 264 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 265 | } |