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 | |
Yuta HIGUCHI | e3ae821 | 2017-04-20 10:18:41 -0700 | [diff] [blame] | 17 | package org.onosproject.netconf.ctl.impl; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 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 ch.ethz.ssh2.Connection; |
| 21 | import ch.ethz.ssh2.Session; |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 22 | import ch.ethz.ssh2.channel.Channel; |
Yuta HIGUCHI | 0976bc2 | 2017-04-20 16:48:20 -0700 | [diff] [blame] | 23 | |
| 24 | import com.google.common.base.MoreObjects; |
| 25 | import com.google.common.base.Objects; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 26 | import com.google.common.base.Preconditions; |
Andrea Campanella | 7bbe7b1 | 2017-05-03 16:03:38 -0700 | [diff] [blame] | 27 | import org.onosproject.netconf.NetconfSessionFactory; |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 28 | import org.onosproject.netconf.DatastoreId; |
Yuta HIGUCHI | e3ae821 | 2017-04-20 10:18:41 -0700 | [diff] [blame] | 29 | import org.onosproject.netconf.FilteringNetconfDeviceOutputEventListener; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 30 | import org.onosproject.netconf.NetconfDeviceInfo; |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 31 | import org.onosproject.netconf.NetconfDeviceOutputEvent; |
Yuta HIGUCHI | 0976bc2 | 2017-04-20 16:48:20 -0700 | [diff] [blame] | 32 | import org.onosproject.netconf.NetconfDeviceOutputEvent.Type; |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 33 | import org.onosproject.netconf.NetconfDeviceOutputEventListener; |
| 34 | import org.onosproject.netconf.NetconfException; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 35 | import org.onosproject.netconf.NetconfSession; |
| 36 | import org.slf4j.Logger; |
| 37 | import org.slf4j.LoggerFactory; |
| 38 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 39 | import java.io.IOException; |
Andreas Papazois | d4712e2 | 2016-02-10 15:59:55 +0200 | [diff] [blame] | 40 | import java.util.ArrayList; |
Yuta HIGUCHI | 0976bc2 | 2017-04-20 16:48:20 -0700 | [diff] [blame] | 41 | import java.util.Collection; |
Andrea Campanella | 1cd641b | 2015-12-07 17:28:34 -0800 | [diff] [blame] | 42 | import java.util.Collections; |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 43 | import java.util.LinkedHashSet; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 44 | import java.util.List; |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 45 | import java.util.Map; |
Andreas Papazois | d4712e2 | 2016-02-10 15:59:55 +0200 | [diff] [blame] | 46 | import java.util.Optional; |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 47 | import java.util.Set; |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 48 | import java.util.concurrent.CompletableFuture; |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 49 | import java.util.concurrent.ConcurrentHashMap; |
Yuta HIGUCHI | 0976bc2 | 2017-04-20 16:48:20 -0700 | [diff] [blame] | 50 | import java.util.concurrent.CopyOnWriteArrayList; |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 51 | import java.util.concurrent.ExecutionException; |
| 52 | import java.util.concurrent.TimeUnit; |
| 53 | import java.util.concurrent.TimeoutException; |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 54 | import java.util.concurrent.atomic.AtomicInteger; |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 55 | |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 56 | import java.util.regex.Pattern; |
| 57 | import java.util.regex.Matcher; |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 58 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 59 | /** |
| 60 | * Implementation of a NETCONF session to talk to a device. |
| 61 | */ |
| 62 | public class NetconfSessionImpl implements NetconfSession { |
| 63 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 64 | private static final Logger log = LoggerFactory |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 65 | .getLogger(NetconfSessionImpl.class); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 66 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 67 | private static final String ENDPATTERN = "]]>]]>"; |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 68 | private static final String MESSAGE_ID_STRING = "message-id"; |
Andrea Campanella | 1311ea0 | 2016-03-04 17:51:25 -0800 | [diff] [blame] | 69 | private static final String HELLO = "<hello"; |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 70 | private static final String NEW_LINE = "\n"; |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 71 | private static final String END_OF_RPC_OPEN_TAG = "\">"; |
| 72 | private static final String EQUAL = "="; |
| 73 | private static final String NUMBER_BETWEEN_QUOTES_MATCHER = "\"+([0-9]+)+\""; |
Akihiro Yamanouchi | 5e5d4df | 2016-06-08 17:06:33 +0900 | [diff] [blame] | 74 | private static final String RPC_OPEN = "<rpc "; |
| 75 | private static final String RPC_CLOSE = "</rpc>"; |
| 76 | private static final String GET_OPEN = "<get>"; |
| 77 | private static final String GET_CLOSE = "</get>"; |
| 78 | private static final String WITH_DEFAULT_OPEN = "<with-defaults "; |
| 79 | private static final String WITH_DEFAULT_CLOSE = "</with-defaults>"; |
Akihiro Yamanouchi | d491284 | 2016-07-01 10:38:46 +0900 | [diff] [blame] | 80 | private static final String DEFAULT_OPERATION_OPEN = "<default-operation>"; |
| 81 | private static final String DEFAULT_OPERATION_CLOSE = "</default-operation>"; |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 82 | private static final String SUBTREE_FILTER_OPEN = "<filter type=\"subtree\">"; |
| 83 | private static final String SUBTREE_FILTER_CLOSE = "</filter>"; |
Akihiro Yamanouchi | d491284 | 2016-07-01 10:38:46 +0900 | [diff] [blame] | 84 | private static final String EDIT_CONFIG_OPEN = "<edit-config>"; |
| 85 | private static final String EDIT_CONFIG_CLOSE = "</edit-config>"; |
| 86 | private static final String TARGET_OPEN = "<target>"; |
| 87 | private static final String TARGET_CLOSE = "</target>"; |
Sean Condon | b0720e7 | 2017-01-10 12:29:02 +0000 | [diff] [blame] | 88 | private static final String CONFIG_OPEN = "<config xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"; |
Akihiro Yamanouchi | d491284 | 2016-07-01 10:38:46 +0900 | [diff] [blame] | 89 | private static final String CONFIG_CLOSE = "</config>"; |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 90 | private static final String XML_HEADER = |
| 91 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; |
Akihiro Yamanouchi | 5e5d4df | 2016-06-08 17:06:33 +0900 | [diff] [blame] | 92 | private static final String NETCONF_BASE_NAMESPACE = |
| 93 | "xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\""; |
| 94 | private static final String NETCONF_WITH_DEFAULTS_NAMESPACE = |
| 95 | "xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-with-defaults\""; |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 96 | private static final String SUBSCRIPTION_SUBTREE_FILTER_OPEN = |
| 97 | "<filter xmlns:base10=\"urn:ietf:params:xml:ns:netconf:base:1.0\" base10:type=\"subtree\">"; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 98 | |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 99 | private static final String INTERLEAVE_CAPABILITY_STRING = "urn:ietf:params:netconf:capability:interleave:1.0"; |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 100 | |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 101 | private static final String CAPABILITY_REGEX = "<capability>\\s*(.*?)\\s*</capability>"; |
| 102 | private static final Pattern CAPABILITY_REGEX_PATTERN = Pattern.compile(CAPABILITY_REGEX); |
| 103 | |
| 104 | private static final String SESSION_ID_REGEX = "<session-id>\\s*(.*?)\\s*</session-id>"; |
| 105 | private static final Pattern SESSION_ID_REGEX_PATTERN = Pattern.compile(SESSION_ID_REGEX); |
| 106 | |
| 107 | private String sessionID; |
Andrea Campanella | 7bbe7b1 | 2017-05-03 16:03:38 -0700 | [diff] [blame] | 108 | private final AtomicInteger messageIdInteger = new AtomicInteger(1); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 109 | private Connection netconfConnection; |
Yuta HIGUCHI | 0976bc2 | 2017-04-20 16:48:20 -0700 | [diff] [blame] | 110 | protected final NetconfDeviceInfo deviceInfo; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 111 | private Session sshSession; |
| 112 | private boolean connectionActive; |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 113 | private Iterable<String> onosCapabilities = |
Andrea Campanella | 1cd641b | 2015-12-07 17:28:34 -0800 | [diff] [blame] | 114 | Collections.singletonList("urn:ietf:params:netconf:base:1.0"); |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 115 | |
| 116 | /* NOTE: the "serverHelloResponseOld" is deprecated in 1.10.0 and should eventually be removed */ |
| 117 | @Deprecated |
| 118 | private String serverHelloResponseOld; |
| 119 | private final Set<String> deviceCapabilities = new LinkedHashSet<>(); |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 120 | private NetconfStreamHandler streamHandler; |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 121 | private Map<Integer, CompletableFuture<String>> replies; |
Andreas Papazois | d4712e2 | 2016-02-10 15:59:55 +0200 | [diff] [blame] | 122 | private List<String> errorReplies; |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 123 | private boolean subscriptionConnected = false; |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 124 | private String notificationFilterSchema = null; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 125 | |
Yuta HIGUCHI | 0976bc2 | 2017-04-20 16:48:20 -0700 | [diff] [blame] | 126 | private final Collection<NetconfDeviceOutputEventListener> primaryListeners = |
| 127 | new CopyOnWriteArrayList<>(); |
| 128 | private final Collection<NetconfSession> children = |
| 129 | new CopyOnWriteArrayList<>(); |
| 130 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 131 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 132 | public NetconfSessionImpl(NetconfDeviceInfo deviceInfo) throws NetconfException { |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 133 | this.deviceInfo = deviceInfo; |
Akihiro Yamanouchi | 5e5d4df | 2016-06-08 17:06:33 +0900 | [diff] [blame] | 134 | this.netconfConnection = null; |
| 135 | this.sshSession = null; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 136 | connectionActive = false; |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 137 | replies = new ConcurrentHashMap<>(); |
Andreas Papazois | d4712e2 | 2016-02-10 15:59:55 +0200 | [diff] [blame] | 138 | errorReplies = new ArrayList<>(); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 139 | startConnection(); |
| 140 | } |
| 141 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 142 | private void startConnection() throws NetconfException { |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 143 | if (!connectionActive) { |
| 144 | netconfConnection = new Connection(deviceInfo.ip().toString(), deviceInfo.port()); |
Sean Condon | 334ad69 | 2016-12-13 17:56:56 +0000 | [diff] [blame] | 145 | int connectTimeout = NetconfControllerImpl.netconfConnectTimeout; |
| 146 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 147 | try { |
Sean Condon | 334ad69 | 2016-12-13 17:56:56 +0000 | [diff] [blame] | 148 | netconfConnection.connect(null, 1000 * connectTimeout, 1000 * connectTimeout); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 149 | } catch (IOException e) { |
Yuta HIGUCHI | 0184a7b | 2017-03-31 13:13:58 -0700 | [diff] [blame] | 150 | throw new NetconfException("Cannot open a connection with device " + deviceInfo, e); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 151 | } |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 152 | boolean isAuthenticated; |
| 153 | try { |
Andrea Campanella | e7006dc | 2017-02-15 16:04:09 -0800 | [diff] [blame] | 154 | if (deviceInfo.getKeyFile() != null && deviceInfo.getKeyFile().canRead()) { |
| 155 | log.debug("Authenticating with key file to device {} with username {}", |
| 156 | deviceInfo.getDeviceId(), deviceInfo.name()); |
| 157 | isAuthenticated = netconfConnection.authenticateWithPublicKey( |
| 158 | deviceInfo.name(), deviceInfo.getKeyFile(), |
| 159 | deviceInfo.password().equals("") ? null : deviceInfo.password()); |
| 160 | } else if (deviceInfo.getKey() != null) { |
Himanshu Ranjan | 7c2ee3c | 2017-02-13 05:10:08 -0600 | [diff] [blame] | 161 | log.debug("Authenticating with key to device {} with username {}", |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 162 | deviceInfo.getDeviceId(), deviceInfo.name()); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 163 | isAuthenticated = netconfConnection.authenticateWithPublicKey( |
Himanshu Ranjan | 7c2ee3c | 2017-02-13 05:10:08 -0600 | [diff] [blame] | 164 | deviceInfo.name(), deviceInfo.getKey(), |
| 165 | deviceInfo.password().equals("") ? null : deviceInfo.password()); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 166 | } else { |
Himanshu Ranjan | 7c2ee3c | 2017-02-13 05:10:08 -0600 | [diff] [blame] | 167 | log.debug("Authenticating to device {} with username {} with password", |
Andrea Campanella | 50d2521 | 2016-02-26 13:06:23 -0800 | [diff] [blame] | 168 | deviceInfo.getDeviceId(), deviceInfo.name()); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 169 | isAuthenticated = netconfConnection.authenticateWithPassword( |
| 170 | deviceInfo.name(), deviceInfo.password()); |
| 171 | } |
| 172 | } catch (IOException e) { |
Ryan Goulding | 6952439 | 2016-12-03 13:21:20 -0500 | [diff] [blame] | 173 | log.error("Authentication connection to device {} failed", |
| 174 | deviceInfo.getDeviceId(), e); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 175 | throw new NetconfException("Authentication connection to device " + |
| 176 | deviceInfo.getDeviceId() + " failed", e); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | connectionActive = true; |
| 180 | Preconditions.checkArgument(isAuthenticated, |
Andrea Campanella | d264b49 | 2016-03-01 09:46:06 -0800 | [diff] [blame] | 181 | "Authentication to device %s with username " + |
| 182 | "%s failed", |
Andrea Campanella | 50d2521 | 2016-02-26 13:06:23 -0800 | [diff] [blame] | 183 | deviceInfo.getDeviceId(), deviceInfo.name()); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 184 | startSshSession(); |
| 185 | } |
| 186 | } |
| 187 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 188 | private void startSshSession() throws NetconfException { |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 189 | try { |
| 190 | sshSession = netconfConnection.openSession(); |
| 191 | sshSession.startSubSystem("netconf"); |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 192 | streamHandler = new NetconfStreamThread(sshSession.getStdout(), sshSession.getStdin(), |
| 193 | sshSession.getStderr(), deviceInfo, |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 194 | new NetconfSessionDelegateImpl(), |
| 195 | replies); |
Yuta HIGUCHI | e3ae821 | 2017-04-20 10:18:41 -0700 | [diff] [blame] | 196 | this.addDeviceOutputListener(new FilteringNetconfDeviceOutputEventListener(deviceInfo)); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 197 | sendHello(); |
| 198 | } catch (IOException e) { |
Andrea Campanella | 0cee0b6 | 2017-04-03 20:02:54 +0200 | [diff] [blame] | 199 | log.error("Failed to create ch.ethz.ssh2.Session session {} ", e.getMessage()); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 200 | throw new NetconfException("Failed to create ch.ethz.ssh2.Session session with device" + |
| 201 | deviceInfo, e); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 205 | |
| 206 | @Beta |
Yuta HIGUCHI | 0976bc2 | 2017-04-20 16:48:20 -0700 | [diff] [blame] | 207 | protected void startSubscriptionStream(String filterSchema) throws NetconfException { |
| 208 | boolean openNewSession = false; |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 209 | if (!deviceCapabilities.contains(INTERLEAVE_CAPABILITY_STRING)) { |
Yuta HIGUCHI | 0976bc2 | 2017-04-20 16:48:20 -0700 | [diff] [blame] | 210 | log.info("Device {} doesn't support interleave, creating child session", deviceInfo); |
| 211 | openNewSession = true; |
| 212 | |
| 213 | } else if (subscriptionConnected && |
| 214 | notificationFilterSchema != null && |
| 215 | !Objects.equal(filterSchema, notificationFilterSchema)) { |
| 216 | // interleave supported and existing filter is NOT "no filtering" |
| 217 | // and was requested with different filtering schema |
| 218 | log.info("Cannot use existing session for subscription {} ({})", |
| 219 | deviceInfo, filterSchema); |
| 220 | openNewSession = true; |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 221 | } |
Yuta HIGUCHI | 0976bc2 | 2017-04-20 16:48:20 -0700 | [diff] [blame] | 222 | |
| 223 | if (openNewSession) { |
| 224 | log.info("Creating notification session to {} with filter {}", |
| 225 | deviceInfo, filterSchema); |
| 226 | NetconfSession child = new NotificationSession(deviceInfo); |
| 227 | |
| 228 | child.addDeviceOutputListener(new NotificationForwarder()); |
| 229 | |
| 230 | child.startSubscription(filterSchema); |
| 231 | children.add(child); |
| 232 | return; |
| 233 | } |
| 234 | |
| 235 | // request to start interleaved notification session |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 236 | String reply = sendRequest(createSubscriptionString(filterSchema)); |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 237 | if (!checkReply(reply)) { |
| 238 | throw new NetconfException("Subscription not successful with device " |
| 239 | + deviceInfo + " with reply " + reply); |
| 240 | } |
| 241 | subscriptionConnected = true; |
| 242 | } |
| 243 | |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 244 | @Override |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 245 | public void startSubscription() throws NetconfException { |
| 246 | if (!subscriptionConnected) { |
Yuta HIGUCHI | 0976bc2 | 2017-04-20 16:48:20 -0700 | [diff] [blame] | 247 | startSubscriptionStream(null); |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 248 | } |
| 249 | streamHandler.setEnableNotifications(true); |
| 250 | } |
| 251 | |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 252 | @Beta |
| 253 | @Override |
| 254 | public void startSubscription(String filterSchema) throws NetconfException { |
| 255 | if (!subscriptionConnected) { |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 256 | notificationFilterSchema = filterSchema; |
Yuta HIGUCHI | 0976bc2 | 2017-04-20 16:48:20 -0700 | [diff] [blame] | 257 | startSubscriptionStream(filterSchema); |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 258 | } |
| 259 | streamHandler.setEnableNotifications(true); |
| 260 | } |
| 261 | |
| 262 | @Beta |
Yuta HIGUCHI | 0976bc2 | 2017-04-20 16:48:20 -0700 | [diff] [blame] | 263 | protected String createSubscriptionString(String filterSchema) { |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 264 | StringBuilder subscriptionbuffer = new StringBuilder(); |
| 265 | subscriptionbuffer.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"); |
| 266 | subscriptionbuffer.append(" <create-subscription\n"); |
| 267 | subscriptionbuffer.append("xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n"); |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 268 | // FIXME Only subtree filtering supported at the moment. |
| 269 | if (filterSchema != null) { |
| 270 | subscriptionbuffer.append(" "); |
| 271 | subscriptionbuffer.append(SUBSCRIPTION_SUBTREE_FILTER_OPEN).append(NEW_LINE); |
| 272 | subscriptionbuffer.append(filterSchema).append(NEW_LINE); |
| 273 | subscriptionbuffer.append(" "); |
| 274 | subscriptionbuffer.append(SUBTREE_FILTER_CLOSE).append(NEW_LINE); |
| 275 | } |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 276 | subscriptionbuffer.append(" </create-subscription>\n"); |
| 277 | subscriptionbuffer.append("</rpc>\n"); |
| 278 | subscriptionbuffer.append(ENDPATTERN); |
| 279 | return subscriptionbuffer.toString(); |
| 280 | } |
| 281 | |
| 282 | @Override |
| 283 | public void endSubscription() throws NetconfException { |
| 284 | if (subscriptionConnected) { |
| 285 | streamHandler.setEnableNotifications(false); |
| 286 | } else { |
| 287 | throw new NetconfException("Subscription does not exist."); |
| 288 | } |
| 289 | } |
| 290 | |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 291 | private void sendHello() throws NetconfException { |
Andrea Campanella | 7bbe7b1 | 2017-05-03 16:03:38 -0700 | [diff] [blame] | 292 | serverHelloResponseOld = sendRequest(createHelloString(), true); |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 293 | Matcher capabilityMatcher = CAPABILITY_REGEX_PATTERN.matcher(serverHelloResponseOld); |
| 294 | while (capabilityMatcher.find()) { |
| 295 | deviceCapabilities.add(capabilityMatcher.group(1)); |
| 296 | } |
| 297 | sessionID = String.valueOf(-1); |
| 298 | Matcher sessionIDMatcher = SESSION_ID_REGEX_PATTERN.matcher(serverHelloResponseOld); |
| 299 | if (sessionIDMatcher.find()) { |
| 300 | sessionID = sessionIDMatcher.group(1); |
| 301 | } else { |
| 302 | throw new NetconfException("Missing SessionID in server hello " + |
| 303 | "reponse."); |
| 304 | } |
| 305 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | private String createHelloString() { |
| 309 | StringBuilder hellobuffer = new StringBuilder(); |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 310 | hellobuffer.append(XML_HEADER); |
| 311 | hellobuffer.append("\n"); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 312 | hellobuffer.append("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"); |
| 313 | hellobuffer.append(" <capabilities>\n"); |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 314 | onosCapabilities.forEach( |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 315 | cap -> hellobuffer.append(" <capability>") |
| 316 | .append(cap) |
| 317 | .append("</capability>\n")); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 318 | hellobuffer.append(" </capabilities>\n"); |
| 319 | hellobuffer.append("</hello>\n"); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 320 | hellobuffer.append(ENDPATTERN); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 321 | return hellobuffer.toString(); |
| 322 | |
| 323 | } |
| 324 | |
Yuta HIGUCHI | e3ae821 | 2017-04-20 10:18:41 -0700 | [diff] [blame] | 325 | @Override |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 326 | public void checkAndReestablish() throws NetconfException { |
| 327 | if (sshSession.getState() != Channel.STATE_OPEN) { |
Andrea Campanella | 1cd641b | 2015-12-07 17:28:34 -0800 | [diff] [blame] | 328 | try { |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 329 | log.debug("Trying to reopen the Sesion with {}", deviceInfo.getDeviceId()); |
Andrea Campanella | 1cd641b | 2015-12-07 17:28:34 -0800 | [diff] [blame] | 330 | startSshSession(); |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 331 | } catch (IOException | IllegalStateException e) { |
| 332 | log.debug("Trying to reopen the Connection with {}", deviceInfo.getDeviceId()); |
Andrea Campanella | 1cd641b | 2015-12-07 17:28:34 -0800 | [diff] [blame] | 333 | try { |
Andrea Campanella | 0cee0b6 | 2017-04-03 20:02:54 +0200 | [diff] [blame] | 334 | connectionActive = false; |
| 335 | replies.clear(); |
Andrea Campanella | 1cd641b | 2015-12-07 17:28:34 -0800 | [diff] [blame] | 336 | startConnection(); |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 337 | if (subscriptionConnected) { |
| 338 | log.debug("Restarting subscription with {}", deviceInfo.getDeviceId()); |
| 339 | subscriptionConnected = false; |
| 340 | startSubscription(notificationFilterSchema); |
| 341 | } |
Andrea Campanella | 1cd641b | 2015-12-07 17:28:34 -0800 | [diff] [blame] | 342 | } catch (IOException e2) { |
Andrea Campanella | 0cee0b6 | 2017-04-03 20:02:54 +0200 | [diff] [blame] | 343 | log.error("No connection {} for device {}", netconfConnection, e.getMessage()); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 344 | throw new NetconfException("Cannot re-open the connection with device" + deviceInfo, e); |
Andrea Campanella | 1cd641b | 2015-12-07 17:28:34 -0800 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 350 | @Override |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 351 | public String requestSync(String request) throws NetconfException { |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 352 | if (!request.contains(ENDPATTERN)) { |
| 353 | request = request + NEW_LINE + ENDPATTERN; |
| 354 | } |
| 355 | String reply = sendRequest(request); |
Andreas Papazois | 2e557be | 2016-06-04 15:39:56 +0300 | [diff] [blame] | 356 | checkReply(reply); |
| 357 | return reply; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | @Override |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 361 | @Deprecated |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 362 | public CompletableFuture<String> request(String request) { |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 363 | return streamHandler.sendMessage(request); |
| 364 | } |
| 365 | |
| 366 | private CompletableFuture<String> request(String request, int messageId) { |
| 367 | return streamHandler.sendMessage(request, messageId); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | private String sendRequest(String request) throws NetconfException { |
Andrea Campanella | 7bbe7b1 | 2017-05-03 16:03:38 -0700 | [diff] [blame] | 371 | return sendRequest(request, false); |
| 372 | } |
| 373 | |
| 374 | private String sendRequest(String request, boolean isHello) throws NetconfException { |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 375 | checkAndReestablish(); |
Andrea Campanella | 7bbe7b1 | 2017-05-03 16:03:38 -0700 | [diff] [blame] | 376 | int messageId = -1; |
| 377 | if (!isHello) { |
| 378 | messageId = messageIdInteger.getAndIncrement(); |
| 379 | } |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 380 | request = formatRequestMessageId(request, messageId); |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 381 | request = formatXmlHeader(request); |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 382 | CompletableFuture<String> futureReply = request(request, messageId); |
Andreas Papazois | 4752cfa | 2016-04-25 14:52:12 +0300 | [diff] [blame] | 383 | int replyTimeout = NetconfControllerImpl.netconfReplyTimeout; |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 384 | String rp; |
| 385 | try { |
Andreas Papazois | 4752cfa | 2016-04-25 14:52:12 +0300 | [diff] [blame] | 386 | rp = futureReply.get(replyTimeout, TimeUnit.SECONDS); |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 387 | replies.remove(messageId); |
Sean Condon | 7347de9 | 2017-07-21 12:17:25 +0100 | [diff] [blame^] | 388 | } catch (InterruptedException e) { |
| 389 | Thread.currentThread().interrupt(); |
| 390 | throw new NetconfException("Interrupted waiting for reply for request" + request, e); |
| 391 | } catch (TimeoutException e) { |
| 392 | throw new NetconfException("Timed out waiting for reply for request " + request, e); |
| 393 | } catch (ExecutionException e) { |
| 394 | log.warn("Closing session {} for {} due to unexpected Error", sessionID, deviceInfo, e); |
| 395 | |
| 396 | netconfConnection.close(); //Closes the socket which should interrupt NetconfStreamThread |
| 397 | sshSession.close(); |
| 398 | |
| 399 | NetconfDeviceOutputEvent event = new NetconfDeviceOutputEvent( |
| 400 | NetconfDeviceOutputEvent.Type.SESSION_CLOSED, |
| 401 | null, "Closed due to unexpected error " + e.getCause(), |
| 402 | Optional.of(-1), deviceInfo); |
| 403 | publishEvent(event); |
| 404 | replies.clear(); |
| 405 | errorReplies.clear(); |
| 406 | |
| 407 | throw new NetconfException("Closing session " + sessionID + " for " + deviceInfo + |
| 408 | " for request " + request, e); |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 409 | } |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 410 | log.debug("Result {} from request {} to device {}", rp, request, deviceInfo); |
Andrea Campanella | 50d2521 | 2016-02-26 13:06:23 -0800 | [diff] [blame] | 411 | return rp.trim(); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 412 | } |
| 413 | |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 414 | private String formatRequestMessageId(String request, int messageId) { |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 415 | if (request.contains(MESSAGE_ID_STRING)) { |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 416 | //FIXME if application provides his own counting of messages this fails that count |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 417 | request = request.replaceFirst(MESSAGE_ID_STRING + EQUAL + NUMBER_BETWEEN_QUOTES_MATCHER, |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 418 | MESSAGE_ID_STRING + EQUAL + "\"" + messageId + "\""); |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 419 | } else if (!request.contains(MESSAGE_ID_STRING) && !request.contains(HELLO)) { |
| 420 | //FIXME find out a better way to enforce the presence of message-id |
| 421 | request = request.replaceFirst(END_OF_RPC_OPEN_TAG, "\" " + MESSAGE_ID_STRING + EQUAL + "\"" |
Sean Condon | d2c8d47 | 2017-02-17 17:09:39 +0000 | [diff] [blame] | 422 | + messageId + "\"" + ">"); |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 423 | } |
| 424 | return request; |
| 425 | } |
| 426 | |
| 427 | private String formatXmlHeader(String request) { |
| 428 | if (!request.contains(XML_HEADER)) { |
| 429 | //FIXME if application provieds his own XML header of different type there is a clash |
| 430 | request = XML_HEADER + "\n" + request; |
| 431 | } |
| 432 | return request; |
| 433 | } |
| 434 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 435 | @Override |
Akihiro Yamanouchi | 8d3a9d3 | 2016-07-12 11:41:44 +0900 | [diff] [blame] | 436 | public String doWrappedRpc(String request) throws NetconfException { |
| 437 | StringBuilder rpc = new StringBuilder(XML_HEADER); |
| 438 | rpc.append(RPC_OPEN); |
| 439 | rpc.append(MESSAGE_ID_STRING); |
| 440 | rpc.append(EQUAL); |
| 441 | rpc.append("\""); |
| 442 | rpc.append(messageIdInteger.get()); |
| 443 | rpc.append("\" "); |
| 444 | rpc.append(NETCONF_BASE_NAMESPACE).append(">\n"); |
| 445 | rpc.append(request); |
| 446 | rpc.append(RPC_CLOSE).append(NEW_LINE); |
| 447 | rpc.append(ENDPATTERN); |
| 448 | String reply = sendRequest(rpc.toString()); |
| 449 | checkReply(reply); |
| 450 | return reply; |
| 451 | } |
| 452 | |
| 453 | @Override |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 454 | public String get(String request) throws NetconfException { |
| 455 | return requestSync(request); |
| 456 | } |
| 457 | |
| 458 | @Override |
Akihiro Yamanouchi | 5e5d4df | 2016-06-08 17:06:33 +0900 | [diff] [blame] | 459 | public String get(String filterSchema, String withDefaultsMode) throws NetconfException { |
| 460 | StringBuilder rpc = new StringBuilder(XML_HEADER); |
| 461 | rpc.append(RPC_OPEN); |
| 462 | rpc.append(MESSAGE_ID_STRING); |
| 463 | rpc.append(EQUAL); |
| 464 | rpc.append("\""); |
| 465 | rpc.append(messageIdInteger.get()); |
| 466 | rpc.append("\" "); |
| 467 | rpc.append(NETCONF_BASE_NAMESPACE).append(">\n"); |
| 468 | rpc.append(GET_OPEN).append(NEW_LINE); |
| 469 | if (filterSchema != null) { |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 470 | rpc.append(SUBTREE_FILTER_OPEN).append(NEW_LINE); |
Akihiro Yamanouchi | 5e5d4df | 2016-06-08 17:06:33 +0900 | [diff] [blame] | 471 | rpc.append(filterSchema).append(NEW_LINE); |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 472 | rpc.append(SUBTREE_FILTER_CLOSE).append(NEW_LINE); |
Akihiro Yamanouchi | 5e5d4df | 2016-06-08 17:06:33 +0900 | [diff] [blame] | 473 | } |
| 474 | if (withDefaultsMode != null) { |
| 475 | rpc.append(WITH_DEFAULT_OPEN).append(NETCONF_WITH_DEFAULTS_NAMESPACE).append(">"); |
| 476 | rpc.append(withDefaultsMode).append(WITH_DEFAULT_CLOSE).append(NEW_LINE); |
| 477 | } |
| 478 | rpc.append(GET_CLOSE).append(NEW_LINE); |
| 479 | rpc.append(RPC_CLOSE).append(NEW_LINE); |
| 480 | rpc.append(ENDPATTERN); |
| 481 | String reply = sendRequest(rpc.toString()); |
| 482 | checkReply(reply); |
| 483 | return reply; |
| 484 | } |
| 485 | |
| 486 | @Override |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 487 | public String getConfig(DatastoreId netconfTargetConfig) throws NetconfException { |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 488 | return getConfig(netconfTargetConfig, null); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | @Override |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 492 | public String getConfig(DatastoreId netconfTargetConfig, |
| 493 | String configurationSchema) throws NetconfException { |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 494 | StringBuilder rpc = new StringBuilder(XML_HEADER); |
| 495 | rpc.append("<rpc "); |
| 496 | rpc.append(MESSAGE_ID_STRING); |
| 497 | rpc.append(EQUAL); |
| 498 | rpc.append("\""); |
| 499 | rpc.append(messageIdInteger.get()); |
| 500 | rpc.append("\" "); |
| 501 | rpc.append("xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 502 | rpc.append("<get-config>\n"); |
| 503 | rpc.append("<source>\n"); |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 504 | rpc.append("<").append(netconfTargetConfig).append("/>"); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 505 | rpc.append("</source>"); |
| 506 | if (configurationSchema != null) { |
| 507 | rpc.append("<filter type=\"subtree\">\n"); |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 508 | rpc.append(configurationSchema).append("\n"); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 509 | rpc.append("</filter>\n"); |
| 510 | } |
| 511 | rpc.append("</get-config>\n"); |
| 512 | rpc.append("</rpc>\n"); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 513 | rpc.append(ENDPATTERN); |
| 514 | String reply = sendRequest(rpc.toString()); |
Andrea Campanella | 1cd641b | 2015-12-07 17:28:34 -0800 | [diff] [blame] | 515 | return checkReply(reply) ? reply : "ERROR " + reply; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | @Override |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 519 | public boolean editConfig(String newConfiguration) throws NetconfException { |
| 520 | newConfiguration = newConfiguration + ENDPATTERN; |
| 521 | return checkReply(sendRequest(newConfiguration)); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | @Override |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 525 | public boolean editConfig(DatastoreId netconfTargetConfig, String mode, String newConfiguration) |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 526 | throws NetconfException { |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 527 | newConfiguration = newConfiguration.trim(); |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 528 | StringBuilder rpc = new StringBuilder(XML_HEADER); |
Akihiro Yamanouchi | d491284 | 2016-07-01 10:38:46 +0900 | [diff] [blame] | 529 | rpc.append(RPC_OPEN); |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 530 | rpc.append(MESSAGE_ID_STRING); |
| 531 | rpc.append(EQUAL); |
| 532 | rpc.append("\""); |
| 533 | rpc.append(messageIdInteger.get()); |
| 534 | rpc.append("\" "); |
Akihiro Yamanouchi | d491284 | 2016-07-01 10:38:46 +0900 | [diff] [blame] | 535 | rpc.append(NETCONF_BASE_NAMESPACE).append(">\n"); |
| 536 | rpc.append(EDIT_CONFIG_OPEN).append("\n"); |
| 537 | rpc.append(TARGET_OPEN); |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 538 | rpc.append("<").append(netconfTargetConfig).append("/>"); |
Akihiro Yamanouchi | d491284 | 2016-07-01 10:38:46 +0900 | [diff] [blame] | 539 | rpc.append(TARGET_CLOSE).append("\n"); |
| 540 | if (mode != null) { |
| 541 | rpc.append(DEFAULT_OPERATION_OPEN); |
| 542 | rpc.append(mode); |
| 543 | rpc.append(DEFAULT_OPERATION_CLOSE).append("\n"); |
| 544 | } |
| 545 | rpc.append(CONFIG_OPEN).append("\n"); |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 546 | rpc.append(newConfiguration); |
Akihiro Yamanouchi | d491284 | 2016-07-01 10:38:46 +0900 | [diff] [blame] | 547 | rpc.append(CONFIG_CLOSE).append("\n"); |
| 548 | rpc.append(EDIT_CONFIG_CLOSE).append("\n"); |
| 549 | rpc.append(RPC_CLOSE); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 550 | rpc.append(ENDPATTERN); |
Konstantinos Kanonakis | 1b8b559 | 2016-09-09 14:34:37 -0500 | [diff] [blame] | 551 | log.debug(rpc.toString()); |
Akihiro Yamanouchi | d491284 | 2016-07-01 10:38:46 +0900 | [diff] [blame] | 552 | String reply = sendRequest(rpc.toString()); |
| 553 | return checkReply(reply); |
Andrea Campanella | f4fd035 | 2015-12-14 17:03:05 -0800 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | @Override |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 557 | public boolean copyConfig(DatastoreId destination, |
| 558 | DatastoreId source) |
| 559 | throws NetconfException { |
| 560 | return bareCopyConfig(destination.asXml(), source.asXml()); |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | @Override |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 564 | public boolean copyConfig(DatastoreId netconfTargetConfig, |
| 565 | String newConfiguration) |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 566 | throws NetconfException { |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 567 | return bareCopyConfig(netconfTargetConfig.asXml(), |
| 568 | normalizeCopyConfigParam(newConfiguration)); |
| 569 | } |
| 570 | |
| 571 | @Override |
| 572 | public boolean copyConfig(String netconfTargetConfig, |
| 573 | String newConfiguration) throws NetconfException { |
| 574 | return bareCopyConfig(normalizeCopyConfigParam(netconfTargetConfig), |
| 575 | normalizeCopyConfigParam(newConfiguration)); |
| 576 | } |
| 577 | |
| 578 | /** |
| 579 | * Normalize String parameter passed to copy-config API. |
| 580 | * <p> |
| 581 | * Provided for backward compatibility purpose |
| 582 | * |
| 583 | * @param input passed to copyConfig API |
| 584 | * @return XML likely to be suitable for copy-config source or target |
| 585 | */ |
| 586 | private static CharSequence normalizeCopyConfigParam(String input) { |
| 587 | input = input.trim(); |
| 588 | if (input.startsWith("<url")) { |
| 589 | return input; |
| 590 | } else if (!input.startsWith("<")) { |
| 591 | // assume it is a datastore name |
| 592 | return DatastoreId.datastore(input).asXml(); |
| 593 | } else if (!input.startsWith("<config>")) { |
| 594 | return "<config>" + input + "</config>"; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 595 | } |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 596 | return input; |
| 597 | } |
| 598 | |
| 599 | private boolean bareCopyConfig(CharSequence target, |
| 600 | CharSequence source) |
| 601 | throws NetconfException { |
| 602 | |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 603 | StringBuilder rpc = new StringBuilder(XML_HEADER); |
yoonseon | 55faf85 | 2016-11-02 14:59:12 -0400 | [diff] [blame] | 604 | rpc.append(RPC_OPEN); |
| 605 | rpc.append(NETCONF_BASE_NAMESPACE).append(">\n"); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 606 | rpc.append("<copy-config>"); |
| 607 | rpc.append("<target>"); |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 608 | rpc.append(target); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 609 | rpc.append("</target>"); |
| 610 | rpc.append("<source>"); |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 611 | rpc.append(source); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 612 | rpc.append("</source>"); |
| 613 | rpc.append("</copy-config>"); |
| 614 | rpc.append("</rpc>"); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 615 | rpc.append(ENDPATTERN); |
| 616 | return checkReply(sendRequest(rpc.toString())); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | @Override |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 620 | public boolean deleteConfig(DatastoreId netconfTargetConfig) throws NetconfException { |
| 621 | if (netconfTargetConfig.equals(DatastoreId.RUNNING)) { |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 622 | log.warn("Target configuration for delete operation can't be \"running\"", |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 623 | netconfTargetConfig); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 624 | return false; |
| 625 | } |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 626 | StringBuilder rpc = new StringBuilder(XML_HEADER); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 627 | rpc.append("<rpc>"); |
| 628 | rpc.append("<delete-config>"); |
| 629 | rpc.append("<target>"); |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 630 | rpc.append("<").append(netconfTargetConfig).append("/>"); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 631 | rpc.append("</target>"); |
| 632 | rpc.append("</delete-config>"); |
| 633 | rpc.append("</rpc>"); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 634 | rpc.append(ENDPATTERN); |
| 635 | return checkReply(sendRequest(rpc.toString())); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | @Override |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 639 | public boolean lock(DatastoreId configType) throws NetconfException { |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 640 | StringBuilder rpc = new StringBuilder(XML_HEADER); |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 641 | rpc.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 642 | rpc.append("<lock>"); |
| 643 | rpc.append("<target>"); |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 644 | rpc.append("<"); |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 645 | rpc.append(configType.id()); |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 646 | rpc.append("/>"); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 647 | rpc.append("</target>"); |
| 648 | rpc.append("</lock>"); |
| 649 | rpc.append("</rpc>"); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 650 | rpc.append(ENDPATTERN); |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 651 | String lockReply = sendRequest(rpc.toString()); |
| 652 | return checkReply(lockReply); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | @Override |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 656 | public boolean unlock(DatastoreId configType) throws NetconfException { |
Andrea Campanella | b029b9e | 2016-01-29 11:05:36 -0800 | [diff] [blame] | 657 | StringBuilder rpc = new StringBuilder(XML_HEADER); |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 658 | rpc.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n"); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 659 | rpc.append("<unlock>"); |
| 660 | rpc.append("<target>"); |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 661 | rpc.append("<"); |
Yuta HIGUCHI | 89111d9 | 2017-05-04 11:29:17 -0700 | [diff] [blame] | 662 | rpc.append(configType.id()); |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 663 | rpc.append("/>"); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 664 | rpc.append("</target>"); |
| 665 | rpc.append("</unlock>"); |
| 666 | rpc.append("</rpc>"); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 667 | rpc.append(ENDPATTERN); |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 668 | String unlockReply = sendRequest(rpc.toString()); |
| 669 | return checkReply(unlockReply); |
| 670 | } |
| 671 | |
| 672 | @Override |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 673 | public boolean close() throws NetconfException { |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 674 | return close(false); |
| 675 | } |
| 676 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 677 | private boolean close(boolean force) throws NetconfException { |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 678 | StringBuilder rpc = new StringBuilder(); |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 679 | rpc.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">"); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 680 | if (force) { |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 681 | rpc.append("<kill-session/>"); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 682 | } else { |
Andrea Campanella | 7e6200a | 2016-03-21 09:48:40 -0700 | [diff] [blame] | 683 | rpc.append("<close-session/>"); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 684 | } |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 685 | rpc.append("</rpc>"); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 686 | rpc.append(ENDPATTERN); |
| 687 | return checkReply(sendRequest(rpc.toString())) || close(true); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | @Override |
| 691 | public String getSessionId() { |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 692 | return sessionID; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | @Override |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 696 | public Set<String> getDeviceCapabilitiesSet() { |
| 697 | return Collections.unmodifiableSet(deviceCapabilities); |
| 698 | } |
| 699 | |
| 700 | @Deprecated |
| 701 | @Override |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 702 | public String getServerCapabilities() { |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 703 | return serverHelloResponseOld; |
| 704 | } |
| 705 | |
| 706 | @Deprecated |
| 707 | @Override |
| 708 | public void setDeviceCapabilities(List<String> capabilities) { |
| 709 | onosCapabilities = capabilities; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | @Override |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 713 | public void setOnosCapabilities(Iterable<String> capabilities) { |
| 714 | onosCapabilities = capabilities; |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Aaron Kruglikov | 72db642 | 2017-02-13 12:16:51 -0800 | [diff] [blame] | 717 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 718 | @Override |
| 719 | public void addDeviceOutputListener(NetconfDeviceOutputEventListener listener) { |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 720 | streamHandler.addDeviceEventListener(listener); |
Yuta HIGUCHI | 0976bc2 | 2017-04-20 16:48:20 -0700 | [diff] [blame] | 721 | primaryListeners.add(listener); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | @Override |
| 725 | public void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener) { |
Yuta HIGUCHI | 0976bc2 | 2017-04-20 16:48:20 -0700 | [diff] [blame] | 726 | primaryListeners.remove(listener); |
helenyrwu | 0407c64 | 2016-06-09 12:01:30 -0700 | [diff] [blame] | 727 | streamHandler.removeDeviceEventListener(listener); |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | private boolean checkReply(String reply) throws NetconfException { |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 731 | if (reply != null) { |
| 732 | if (!reply.contains("<rpc-error>")) { |
Akihiro Yamanouchi | d491284 | 2016-07-01 10:38:46 +0900 | [diff] [blame] | 733 | log.debug("Device {} sent reply {}", deviceInfo, reply); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 734 | return true; |
| 735 | } else if (reply.contains("<ok/>") |
| 736 | || (reply.contains("<rpc-error>") |
| 737 | && reply.contains("warning"))) { |
Akihiro Yamanouchi | d491284 | 2016-07-01 10:38:46 +0900 | [diff] [blame] | 738 | log.debug("Device {} sent reply {}", deviceInfo, reply); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 739 | return true; |
| 740 | } |
| 741 | } |
Andrea Campanella | d264b49 | 2016-03-01 09:46:06 -0800 | [diff] [blame] | 742 | log.warn("Device {} has error in reply {}", deviceInfo, reply); |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 743 | return false; |
| 744 | } |
| 745 | |
Sean Condon | 7347de9 | 2017-07-21 12:17:25 +0100 | [diff] [blame^] | 746 | protected void publishEvent(NetconfDeviceOutputEvent event) { |
| 747 | primaryListeners.forEach(lsnr -> { |
| 748 | if (lsnr.isRelevant(event)) { |
| 749 | lsnr.event(event); |
| 750 | } |
| 751 | }); |
| 752 | } |
| 753 | |
Yuta HIGUCHI | 0976bc2 | 2017-04-20 16:48:20 -0700 | [diff] [blame] | 754 | static class NotificationSession extends NetconfSessionImpl { |
| 755 | |
| 756 | private String notificationFilter; |
| 757 | |
| 758 | NotificationSession(NetconfDeviceInfo deviceInfo) |
| 759 | throws NetconfException { |
| 760 | super(deviceInfo); |
| 761 | } |
| 762 | |
| 763 | @Override |
| 764 | protected void startSubscriptionStream(String filterSchema) |
| 765 | throws NetconfException { |
| 766 | |
| 767 | notificationFilter = filterSchema; |
| 768 | requestSync(createSubscriptionString(filterSchema)); |
| 769 | } |
| 770 | |
| 771 | @Override |
| 772 | public String toString() { |
| 773 | return MoreObjects.toStringHelper(getClass()) |
| 774 | .add("deviceInfo", deviceInfo) |
| 775 | .add("sessionID", getSessionId()) |
| 776 | .add("notificationFilter", notificationFilter) |
| 777 | .toString(); |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | /** |
| 782 | * Listener attached to child session for notification streaming. |
| 783 | * |
| 784 | * Forwards all notification event from child session to primary session |
| 785 | * listeners. |
| 786 | */ |
| 787 | private final class NotificationForwarder |
| 788 | implements NetconfDeviceOutputEventListener { |
| 789 | |
| 790 | @Override |
| 791 | public boolean isRelevant(NetconfDeviceOutputEvent event) { |
| 792 | return event.type() == Type.DEVICE_NOTIFICATION; |
| 793 | } |
| 794 | |
| 795 | @Override |
| 796 | public void event(NetconfDeviceOutputEvent event) { |
Sean Condon | 7347de9 | 2017-07-21 12:17:25 +0100 | [diff] [blame^] | 797 | publishEvent(event); |
Yuta HIGUCHI | 0976bc2 | 2017-04-20 16:48:20 -0700 | [diff] [blame] | 798 | } |
| 799 | } |
| 800 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 801 | public class NetconfSessionDelegateImpl implements NetconfSessionDelegate { |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 802 | |
Andrea Campanella | 101417d | 2015-12-11 17:58:07 -0800 | [diff] [blame] | 803 | @Override |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame] | 804 | public void notify(NetconfDeviceOutputEvent event) { |
Andreas Papazois | d4712e2 | 2016-02-10 15:59:55 +0200 | [diff] [blame] | 805 | Optional<Integer> messageId = event.getMessageID(); |
Andrea Campanella | 0cee0b6 | 2017-04-03 20:02:54 +0200 | [diff] [blame] | 806 | log.debug("messageID {}, waiting replies messageIDs {}", messageId, |
| 807 | replies.keySet()); |
Andreas Papazois | d4712e2 | 2016-02-10 15:59:55 +0200 | [diff] [blame] | 808 | if (!messageId.isPresent()) { |
| 809 | errorReplies.add(event.getMessagePayload()); |
Andrea Campanella | d264b49 | 2016-03-01 09:46:06 -0800 | [diff] [blame] | 810 | log.error("Device {} sent error reply {}", |
| 811 | event.getDeviceInfo(), event.getMessagePayload()); |
Andreas Papazois | d4712e2 | 2016-02-10 15:59:55 +0200 | [diff] [blame] | 812 | return; |
| 813 | } |
| 814 | CompletableFuture<String> completedReply = |
| 815 | replies.get(messageId.get()); |
Akihiro Yamanouchi | 4512222 | 2016-07-15 13:13:11 +0900 | [diff] [blame] | 816 | if (completedReply != null) { |
| 817 | completedReply.complete(event.getMessagePayload()); |
| 818 | } |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 819 | } |
| 820 | } |
Andrea Campanella | 7bbe7b1 | 2017-05-03 16:03:38 -0700 | [diff] [blame] | 821 | |
| 822 | public static class SshNetconfSessionFactory implements NetconfSessionFactory { |
| 823 | |
| 824 | @Override |
| 825 | public NetconfSession createNetconfSession(NetconfDeviceInfo netconfDeviceInfo) throws NetconfException { |
| 826 | return new NetconfSessionImpl(netconfDeviceInfo); |
| 827 | } |
| 828 | } |
andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 829 | } |