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