blob: e89449e622f20b8ad733c5bb32e4908398bd51ee [file] [log] [blame]
Andrea Campanella7bbe7b12017-05-03 16:03:38 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Andrea Campanella7bbe7b12017-05-03 16:03:38 -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.ctl.impl;
18
19import com.google.common.annotations.Beta;
20import com.google.common.base.MoreObjects;
21import com.google.common.base.Objects;
Kamil Stasiak9f59f442017-05-02 11:02:24 +020022import com.google.common.collect.ImmutableList;
Andrea Campanella7bbe7b12017-05-03 16:03:38 -070023import com.google.common.collect.ImmutableSet;
quan PHAM VAN32d70e52018-08-01 17:35:30 -070024import com.google.common.collect.Sets;
Andrea Campanella7bbe7b12017-05-03 16:03:38 -070025import org.apache.sshd.client.SshClient;
26import org.apache.sshd.client.channel.ClientChannel;
27import org.apache.sshd.client.future.ConnectFuture;
28import org.apache.sshd.client.future.OpenFuture;
29import org.apache.sshd.client.session.ClientSession;
Sean Condon7347de92017-07-21 12:17:25 +010030import org.apache.sshd.common.FactoryManager;
Andrea Campanella7bbe7b12017-05-03 16:03:38 -070031import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
Holger Schulz092cbbf2017-08-31 17:52:30 +020032import org.bouncycastle.jce.provider.BouncyCastleProvider;
Holger Schulz092cbbf2017-08-31 17:52:30 +020033import org.bouncycastle.openssl.PEMKeyPair;
quan PHAM VAN32d70e52018-08-01 17:35:30 -070034import org.bouncycastle.openssl.PEMParser;
Holger Schulz092cbbf2017-08-31 17:52:30 +020035import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
quan PHAM VAN32d70e52018-08-01 17:35:30 -070036import org.onlab.osgi.DefaultServiceDirectory;
37import org.onlab.osgi.ServiceDirectory;
Andrea Campanellaa2a6c3c2018-12-11 12:56:38 +010038import org.onlab.util.ItemNotFoundException;
Yuta HIGUCHI6e6c26e2017-09-06 14:25:57 -070039import org.onlab.util.SharedExecutors;
quan PHAM VAN32d70e52018-08-01 17:35:30 -070040import org.onosproject.net.DeviceId;
41import org.onosproject.net.driver.Driver;
42import org.onosproject.net.driver.DriverService;
Yuta HIGUCHI4f55c672018-06-14 18:10:43 -070043import org.onosproject.netconf.AbstractNetconfSession;
gyewan.an91d7e7e2019-01-17 15:12:48 +090044import org.onosproject.netconf.NetconfController;
Andrea Campanella7bbe7b12017-05-03 16:03:38 -070045import org.onosproject.netconf.NetconfDeviceInfo;
46import org.onosproject.netconf.NetconfDeviceOutputEvent;
47import org.onosproject.netconf.NetconfDeviceOutputEvent.Type;
48import org.onosproject.netconf.NetconfDeviceOutputEventListener;
49import org.onosproject.netconf.NetconfException;
50import org.onosproject.netconf.NetconfSession;
51import org.onosproject.netconf.NetconfSessionFactory;
Yuta HIGUCHI6e6c26e2017-09-06 14:25:57 -070052import org.onosproject.netconf.NetconfTransportException;
Andrea Campanella7bbe7b12017-05-03 16:03:38 -070053import org.slf4j.Logger;
Yuta HIGUCHI15677982017-08-16 15:50:29 -070054
Holger Schulz092cbbf2017-08-31 17:52:30 +020055import java.io.CharArrayReader;
Andrea Campanella7bbe7b12017-05-03 16:03:38 -070056import java.io.IOException;
Andrea Campanella7bbe7b12017-05-03 16:03:38 -070057import java.security.KeyFactory;
58import java.security.KeyPair;
59import java.security.NoSuchAlgorithmException;
60import java.security.PublicKey;
61import java.security.spec.InvalidKeySpecException;
62import java.security.spec.X509EncodedKeySpec;
quan PHAM VAN32d70e52018-08-01 17:35:30 -070063import java.util.ArrayList;
64import java.util.Arrays;
Andrea Campanella7bbe7b12017-05-03 16:03:38 -070065import java.util.Collection;
66import java.util.Collections;
quan PHAM VAN32d70e52018-08-01 17:35:30 -070067import java.util.LinkedHashSet;
68import java.util.List;
69import java.util.Map;
Andrea Campanella7bbe7b12017-05-03 16:03:38 -070070import java.util.Optional;
quan PHAM VAN32d70e52018-08-01 17:35:30 -070071import java.util.Set;
Andrea Campanella7bbe7b12017-05-03 16:03:38 -070072import java.util.concurrent.CompletableFuture;
73import java.util.concurrent.ConcurrentHashMap;
74import java.util.concurrent.CopyOnWriteArrayList;
75import java.util.concurrent.ExecutionException;
76import java.util.concurrent.TimeUnit;
77import java.util.concurrent.TimeoutException;
78import java.util.concurrent.atomic.AtomicInteger;
79import java.util.regex.Matcher;
80import java.util.regex.Pattern;
81
quan PHAM VAN32d70e52018-08-01 17:35:30 -070082import static java.nio.charset.StandardCharsets.UTF_8;
83import static org.slf4j.LoggerFactory.getLogger;
84
Andrea Campanella7bbe7b12017-05-03 16:03:38 -070085/**
86 * Implementation of a NETCONF session to talk to a device.
87 */
Yuta HIGUCHI4f55c672018-06-14 18:10:43 -070088public class NetconfSessionMinaImpl extends AbstractNetconfSession {
Andrea Campanella7bbe7b12017-05-03 16:03:38 -070089
Yuta HIGUCHI6e6c26e2017-09-06 14:25:57 -070090 private static final Logger log = getLogger(NetconfSessionMinaImpl.class);
Andrea Campanella7bbe7b12017-05-03 16:03:38 -070091
Yuta HIGUCHI371667d2017-09-05 17:30:51 -070092 /**
93 * NC 1.0, RFC4742 EOM sequence.
94 */
Andrea Campanella7bbe7b12017-05-03 16:03:38 -070095 private static final String ENDPATTERN = "]]>]]>";
96 private static final String MESSAGE_ID_STRING = "message-id";
97 private static final String HELLO = "<hello";
98 private static final String NEW_LINE = "\n";
99 private static final String END_OF_RPC_OPEN_TAG = "\">";
100 private static final String EQUAL = "=";
101 private static final String NUMBER_BETWEEN_QUOTES_MATCHER = "\"+([0-9]+)+\"";
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700102 private static final String SUBTREE_FILTER_CLOSE = "</filter>";
Yuta HIGUCHI371667d2017-09-05 17:30:51 -0700103 // FIXME hard coded namespace nc
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700104 private static final String XML_HEADER =
105 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
Yuta HIGUCHI4f55c672018-06-14 18:10:43 -0700106
Yuta HIGUCHI371667d2017-09-05 17:30:51 -0700107 // FIXME hard coded namespace base10
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700108 private static final String SUBSCRIPTION_SUBTREE_FILTER_OPEN =
109 "<filter xmlns:base10=\"urn:ietf:params:xml:ns:netconf:base:1.0\" base10:type=\"subtree\">";
110
111 private static final String INTERLEAVE_CAPABILITY_STRING = "urn:ietf:params:netconf:capability:interleave:1.0";
112
113 private static final String CAPABILITY_REGEX = "<capability>\\s*(.*?)\\s*</capability>";
114 private static final Pattern CAPABILITY_REGEX_PATTERN = Pattern.compile(CAPABILITY_REGEX);
115
116 private static final String SESSION_ID_REGEX = "<session-id>\\s*(.*?)\\s*</session-id>";
117 private static final Pattern SESSION_ID_REGEX_PATTERN = Pattern.compile(SESSION_ID_REGEX);
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200118 private static final String HASH = "#";
119 private static final String LF = "\n";
120 private static final String MSGLEN_REGEX_PATTERN = "\n#\\d+\n";
121 private static final String NETCONF_10_CAPABILITY = "urn:ietf:params:netconf:base:1.0";
122 private static final String NETCONF_11_CAPABILITY = "urn:ietf:params:netconf:base:1.1";
quan PHAM VAN32d70e52018-08-01 17:35:30 -0700123 private static final String NETCONF_CLIENT_CAPABILITY = "netconfClientCapability";
Laszlo Pappbdb64082018-09-11 12:21:29 +0100124 private static final String NOTIFICATION_STREAM = "notificationStream";
quan PHAM VAN32d70e52018-08-01 17:35:30 -0700125
126 private static ServiceDirectory directory = new DefaultServiceDirectory();
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700127
128 private String sessionID;
129 private final AtomicInteger messageIdInteger = new AtomicInteger(1);
130 protected final NetconfDeviceInfo deviceInfo;
131 private Iterable<String> onosCapabilities =
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200132 ImmutableList.of(NETCONF_10_CAPABILITY, NETCONF_11_CAPABILITY);
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700133
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700134 private final Set<String> deviceCapabilities = new LinkedHashSet<>();
135 private NetconfStreamHandler streamHandler;
Yuta HIGUCHI371667d2017-09-05 17:30:51 -0700136 // FIXME ONOS-7019 key type should be revised to a String, see RFC6241
137 /**
138 * Message-ID and corresponding Future waiting for response.
139 */
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700140 private Map<Integer, CompletableFuture<String>> replies;
Sean Condon7347de92017-07-21 12:17:25 +0100141 private List<String> errorReplies; // Not sure why we need this?
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700142 private boolean subscriptionConnected = false;
143 private String notificationFilterSchema = null;
144
145 private final Collection<NetconfDeviceOutputEventListener> primaryListeners =
146 new CopyOnWriteArrayList<>();
147 private final Collection<NetconfSession> children =
148 new CopyOnWriteArrayList<>();
149
Sean Condon54d82432017-07-26 22:27:25 +0100150 private int connectTimeout;
151 private int replyTimeout;
152 private int idleTimeout;
153
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700154 private ClientChannel channel = null;
155 private ClientSession session = null;
156 private SshClient client = null;
157
DongRyeol Chac29f9072018-11-06 14:05:56 +0900158 private boolean disconnected = false;
159
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700160 public NetconfSessionMinaImpl(NetconfDeviceInfo deviceInfo) throws NetconfException {
161 this.deviceInfo = deviceInfo;
162 replies = new ConcurrentHashMap<>();
163 errorReplies = new ArrayList<>();
quan PHAM VAN32d70e52018-08-01 17:35:30 -0700164 Set<String> capabilities = getClientCapabilites(deviceInfo.getDeviceId());
165 if (!capabilities.isEmpty()) {
166 capabilities.addAll(Sets.newHashSet(onosCapabilities));
167 setOnosCapabilities(capabilities);
168 }
Yuta HIGUCHI6e6c26e2017-09-06 14:25:57 -0700169 // FIXME should not immediately start session on construction
170 // setOnosCapabilities() is useless due to this behavior
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700171 startConnection();
172 }
173
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200174 public NetconfSessionMinaImpl(NetconfDeviceInfo deviceInfo, List<String> capabilities) throws NetconfException {
175 this.deviceInfo = deviceInfo;
176 replies = new ConcurrentHashMap<>();
177 errorReplies = new ArrayList<>();
178 setOnosCapabilities(capabilities);
Yuta HIGUCHI6e6c26e2017-09-06 14:25:57 -0700179 // FIXME should not immediately start session on construction
180 // setOnosCapabilities() is useless due to this behavior
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200181 startConnection();
182 }
183
quan PHAM VAN32d70e52018-08-01 17:35:30 -0700184 /**
185 * Get the list of the netconf client capabilities from device driver property.
186 *
187 * @param deviceId the deviceID for which to recover the capabilities from the driver.
188 * @return the String list of clientCapability property, or null if it is not configured
189 */
190 public Set<String> getClientCapabilites(DeviceId deviceId) {
191 Set<String> capabilities = new LinkedHashSet<>();
192 DriverService driverService = directory.get(DriverService.class);
Andrea Campanellaa2a6c3c2018-12-11 12:56:38 +0100193 try {
194 Driver driver = driverService.getDriver(deviceId);
195 if (driver == null) {
196 return capabilities;
197 }
198 String clientCapabilities = driver.getProperty(NETCONF_CLIENT_CAPABILITY);
199 if (clientCapabilities == null) {
200 return capabilities;
201 }
202 String[] textStr = clientCapabilities.split("\\|");
203 capabilities.addAll(Arrays.asList(textStr));
204 return capabilities;
205 } catch (ItemNotFoundException e) {
206 log.warn("Driver for device {} currently not available", deviceId);
quan PHAM VAN32d70e52018-08-01 17:35:30 -0700207 return capabilities;
208 }
quan PHAM VAN32d70e52018-08-01 17:35:30 -0700209 }
210
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700211 private void startConnection() throws NetconfException {
Sean Condon54d82432017-07-26 22:27:25 +0100212 connectTimeout = deviceInfo.getConnectTimeoutSec().orElse(
Andrea Campanella3a361452019-08-02 10:17:53 +0200213 NetconfControllerImpl.netconfConnectTimeout);
Sean Condon54d82432017-07-26 22:27:25 +0100214 replyTimeout = deviceInfo.getReplyTimeoutSec().orElse(
Andrea Campanella3a361452019-08-02 10:17:53 +0200215 NetconfControllerImpl.netconfReplyTimeout);
Sean Condon54d82432017-07-26 22:27:25 +0100216 idleTimeout = deviceInfo.getIdleTimeoutSec().orElse(
Andrea Campanella3a361452019-08-02 10:17:53 +0200217 NetconfControllerImpl.netconfIdleTimeout);
Sean Condon54d82432017-07-26 22:27:25 +0100218 log.info("Connecting to {} with timeouts C:{}, R:{}, I:{}", deviceInfo,
219 connectTimeout, replyTimeout, idleTimeout);
220
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700221 try {
222 startClient();
DongRyeol Chac29f9072018-11-06 14:05:56 +0900223 } catch (Exception e) {
224 stopClient();
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700225 throw new NetconfException("Failed to establish SSH with device " + deviceInfo, e);
226 }
227 }
228
229 private void startClient() throws IOException {
Yuta HIGUCHI2ee4fba2018-06-12 16:21:06 -0700230 log.info("Creating NETCONF session to {}",
Andrea Campanella3a361452019-08-02 10:17:53 +0200231 deviceInfo.getDeviceId());
Yuta HIGUCHI2ee4fba2018-06-12 16:21:06 -0700232
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700233 client = SshClient.setUpDefaultClient();
Andrea Campanella59227c32019-01-07 14:52:35 +0100234 if (idleTimeout != NetconfControllerImpl.netconfIdleTimeout) {
235 client.getProperties().putIfAbsent(FactoryManager.IDLE_TIMEOUT,
236 TimeUnit.SECONDS.toMillis(idleTimeout));
237 client.getProperties().putIfAbsent(FactoryManager.NIO2_READ_TIMEOUT,
238 TimeUnit.SECONDS.toMillis(idleTimeout + 15L));
239 }
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700240 client.start();
241 client.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
242 startSession();
DongRyeol Chac29f9072018-11-06 14:05:56 +0900243
244 disconnected = false;
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700245 }
246
Yuta HIGUCHI4f55c672018-06-14 18:10:43 -0700247 //TODO: Remove the default methods already implemented in NetconfSession
248
Yuta HIGUCHI6e6c26e2017-09-06 14:25:57 -0700249 // FIXME blocking
250 @Deprecated
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700251 private void startSession() throws IOException {
252 final ConnectFuture connectFuture;
253 connectFuture = client.connect(deviceInfo.name(),
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200254 deviceInfo.ip().toString(),
255 deviceInfo.port())
Sean Condon54d82432017-07-26 22:27:25 +0100256 .verify(connectTimeout, TimeUnit.SECONDS);
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700257 session = connectFuture.getSession();
258 //Using the device ssh key if possible
259 if (deviceInfo.getKey() != null) {
Yuta HIGUCHIb2d05242017-09-05 15:44:34 -0700260 try (PEMParser pemParser = new PEMParser(new CharArrayReader(deviceInfo.getKey()))) {
261 JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME);
262 try {
263 KeyPair kp = converter.getKeyPair((PEMKeyPair) pemParser.readObject());
264 session.addPublicKeyIdentity(kp);
265 } catch (IOException e) {
266 throw new NetconfException("Failed to authenticate session with device " +
267 deviceInfo + "check key to be a valid key", e);
268 }
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700269 }
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700270 } else {
271 session.addPasswordIdentity(deviceInfo.password());
272 }
Sean Condon54d82432017-07-26 22:27:25 +0100273 session.auth().verify(connectTimeout, TimeUnit.SECONDS);
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700274 Set<ClientSession.ClientSessionEvent> event = session.waitFor(
275 ImmutableSet.of(ClientSession.ClientSessionEvent.WAIT_AUTH,
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200276 ClientSession.ClientSessionEvent.CLOSED,
277 ClientSession.ClientSessionEvent.AUTHED), 0);
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700278
279 if (!event.contains(ClientSession.ClientSessionEvent.AUTHED)) {
280 log.debug("Session closed {} {}", event, session.isClosed());
281 throw new NetconfException("Failed to authenticate session with device " +
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200282 deviceInfo + "check the user/pwd or key");
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700283 }
284 openChannel();
285 }
286
287 private PublicKey getPublicKey(byte[] keyBytes, String type)
288 throws NoSuchAlgorithmException, InvalidKeySpecException {
289
290 X509EncodedKeySpec spec =
291 new X509EncodedKeySpec(keyBytes);
292 KeyFactory kf = KeyFactory.getInstance(type);
293 return kf.generatePublic(spec);
294 }
295
Yuta HIGUCHI6e6c26e2017-09-06 14:25:57 -0700296 // FIXME blocking
297 @Deprecated
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700298 private void openChannel() throws IOException {
299 channel = session.createSubsystemChannel("netconf");
300 OpenFuture channelFuture = channel.open();
Sean Condon54d82432017-07-26 22:27:25 +0100301 if (channelFuture.await(connectTimeout, TimeUnit.SECONDS)) {
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700302 if (channelFuture.isOpened()) {
303 streamHandler = new NetconfStreamThread(channel.getInvertedOut(), channel.getInvertedIn(),
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200304 channel.getInvertedErr(), deviceInfo,
305 new NetconfSessionDelegateImpl(), replies);
Andrea Campanella59227c32019-01-07 14:52:35 +0100306 primaryListeners.forEach(l -> streamHandler.addDeviceEventListener(l));
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700307 } else {
308 throw new NetconfException("Failed to open channel with device " +
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200309 deviceInfo);
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700310 }
311 sendHello();
312 }
313 }
314
315
316 @Beta
317 protected void startSubscriptionStream(String filterSchema) throws NetconfException {
318 boolean openNewSession = false;
319 if (!deviceCapabilities.contains(INTERLEAVE_CAPABILITY_STRING)) {
320 log.info("Device {} doesn't support interleave, creating child session", deviceInfo);
321 openNewSession = true;
322
323 } else if (subscriptionConnected &&
324 notificationFilterSchema != null &&
325 !Objects.equal(filterSchema, notificationFilterSchema)) {
326 // interleave supported and existing filter is NOT "no filtering"
327 // and was requested with different filtering schema
328 log.info("Cannot use existing session for subscription {} ({})",
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200329 deviceInfo, filterSchema);
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700330 openNewSession = true;
331 }
332
333 if (openNewSession) {
334 log.info("Creating notification session to {} with filter {}",
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200335 deviceInfo, filterSchema);
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700336 NetconfSession child = new NotificationSession(deviceInfo);
337
338 child.addDeviceOutputListener(new NotificationForwarder());
339
340 child.startSubscription(filterSchema);
341 children.add(child);
342 return;
343 }
344
345 // request to start interleaved notification session
346 String reply = sendRequest(createSubscriptionString(filterSchema));
347 if (!checkReply(reply)) {
348 throw new NetconfException("Subscription not successful with device "
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200349 + deviceInfo + " with reply " + reply);
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700350 }
351 subscriptionConnected = true;
352 }
353
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700354 @Beta
355 @Override
356 public void startSubscription(String filterSchema) throws NetconfException {
357 if (!subscriptionConnected) {
358 notificationFilterSchema = filterSchema;
359 startSubscriptionStream(filterSchema);
360 }
361 streamHandler.setEnableNotifications(true);
362 }
363
364 @Beta
365 protected String createSubscriptionString(String filterSchema) {
366 StringBuilder subscriptionbuffer = new StringBuilder();
367 subscriptionbuffer.append("<rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n");
368 subscriptionbuffer.append(" <create-subscription\n");
369 subscriptionbuffer.append("xmlns=\"urn:ietf:params:xml:ns:netconf:notification:1.0\">\n");
Laszlo Pappbdb64082018-09-11 12:21:29 +0100370 DriverService driverService = directory.get(DriverService.class);
371 Driver driver = driverService.getDriver(deviceInfo.getDeviceId());
372 if (driver != null) {
373 String stream = driver.getProperty(NOTIFICATION_STREAM);
374 if (stream != null) {
375 subscriptionbuffer.append(" <stream>");
376 subscriptionbuffer.append(stream);
377 subscriptionbuffer.append("</stream>\n");
378 }
379 }
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700380 // FIXME Only subtree filtering supported at the moment.
381 if (filterSchema != null) {
382 subscriptionbuffer.append(" ");
383 subscriptionbuffer.append(SUBSCRIPTION_SUBTREE_FILTER_OPEN).append(NEW_LINE);
384 subscriptionbuffer.append(filterSchema).append(NEW_LINE);
385 subscriptionbuffer.append(" ");
386 subscriptionbuffer.append(SUBTREE_FILTER_CLOSE).append(NEW_LINE);
387 }
388 subscriptionbuffer.append(" </create-subscription>\n");
389 subscriptionbuffer.append("</rpc>\n");
390 subscriptionbuffer.append(ENDPATTERN);
391 return subscriptionbuffer.toString();
392 }
393
394 @Override
395 public void endSubscription() throws NetconfException {
396 if (subscriptionConnected) {
397 streamHandler.setEnableNotifications(false);
398 } else {
399 throw new NetconfException("Subscription does not exist.");
400 }
401 }
402
DongRyeol Chac29f9072018-11-06 14:05:56 +0900403 private void stopClient() {
404 if (session != null) {
405 try {
406 session.close();
407 } catch (IOException ex) {
408 log.warn("Cannot close session {} {}", sessionID, deviceInfo, ex);
409 }
410 }
411
412 if (channel != null) {
413 try {
414 channel.close();
415 } catch (IOException ex) {
416 log.warn("Cannot close channel {} {}", sessionID, deviceInfo, ex);
417 }
418 }
419
420 if (client != null) {
421 try {
422 client.close();
423 } catch (IOException ex) {
424 log.warn("Cannot close client {} {}", sessionID, deviceInfo, ex);
425 }
426
427 client.stop();
428 }
429 }
430
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700431 private void sendHello() throws NetconfException {
Yuta HIGUCHI371667d2017-09-05 17:30:51 -0700432 String serverHelloResponse = sendRequest(createHelloString(), true);
433 Matcher capabilityMatcher = CAPABILITY_REGEX_PATTERN.matcher(serverHelloResponse);
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700434 while (capabilityMatcher.find()) {
435 deviceCapabilities.add(capabilityMatcher.group(1));
436 }
437 sessionID = String.valueOf(-1);
Yuta HIGUCHI371667d2017-09-05 17:30:51 -0700438 Matcher sessionIDMatcher = SESSION_ID_REGEX_PATTERN.matcher(serverHelloResponse);
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700439 if (sessionIDMatcher.find()) {
440 sessionID = sessionIDMatcher.group(1);
441 } else {
442 throw new NetconfException("Missing SessionID in server hello " +
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200443 "reponse.");
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700444 }
445
446 }
447
448 private String createHelloString() {
449 StringBuilder hellobuffer = new StringBuilder();
450 hellobuffer.append(XML_HEADER);
451 hellobuffer.append("\n");
452 hellobuffer.append("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">\n");
453 hellobuffer.append(" <capabilities>\n");
454 onosCapabilities.forEach(
455 cap -> hellobuffer.append(" <capability>")
456 .append(cap)
457 .append("</capability>\n"));
458 hellobuffer.append(" </capabilities>\n");
459 hellobuffer.append("</hello>\n");
460 hellobuffer.append(ENDPATTERN);
461 return hellobuffer.toString();
462
463 }
464
465 @Override
466 public void checkAndReestablish() throws NetconfException {
DongRyeol Chac29f9072018-11-06 14:05:56 +0900467 if (disconnected) {
468 log.warn("Can't reopen connection for device because of disconnected {}", deviceInfo.getDeviceId());
469 throw new NetconfException("Can't reopen connection for device because of disconnected " + deviceInfo);
470 }
471
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700472 try {
zhongguo zhao98bb37a2018-08-28 16:17:06 +0800473 if (client.isClosed() || client.isClosing()) {
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700474 log.debug("Trying to restart the whole SSH connection with {}", deviceInfo.getDeviceId());
475 cleanUp();
476 startConnection();
zhongguo zhao98bb37a2018-08-28 16:17:06 +0800477 } else if (session.isClosed() || session.isClosing()) {
Kieran McPeakee1b418f2019-05-23 13:42:13 +0100478 log.debug("Trying to restart the session {} with {}", session, deviceInfo.getDeviceId());
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700479 cleanUp();
480 startSession();
zhongguo zhao98bb37a2018-08-28 16:17:06 +0800481 } else if (channel.isClosed() || channel.isClosing()) {
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700482 log.debug("Trying to reopen the channel with {}", deviceInfo.getDeviceId());
483 cleanUp();
484 openChannel();
Andrea Campanella856f3132017-10-23 15:46:36 +0200485 } else {
486 return;
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700487 }
488 if (subscriptionConnected) {
489 log.debug("Restarting subscription with {}", deviceInfo.getDeviceId());
490 subscriptionConnected = false;
491 startSubscription(notificationFilterSchema);
492 }
Sean Condon7347de92017-07-21 12:17:25 +0100493 } catch (IOException | IllegalStateException e) {
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700494 log.error("Can't reopen connection for device {}", e.getMessage());
495 throw new NetconfException("Cannot re-open the connection with device" + deviceInfo, e);
496 }
497 }
498
499 private void cleanUp() {
500 //makes sure everything is at a clean state.
501 replies.clear();
David K. Bainbridge9b582b02019-02-01 16:04:05 -0800502 if (streamHandler != null) {
503 streamHandler.close();
504 }
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700505 }
506
507 @Override
508 public String requestSync(String request) throws NetconfException {
gyewan.an91d7e7e2019-01-17 15:12:48 +0900509 return requestSync(request, replyTimeout);
510 }
511
512 @Override
513 public String requestSync(String request, int timeout) throws NetconfException {
514 String reply = sendRequest(request, timeout);
Kim JeongWoo8b03bc52018-08-10 16:50:23 +0900515 if (!checkReply(reply)) {
516 throw new NetconfException("Request not successful with device "
Andrea Campanella3a361452019-08-02 10:17:53 +0200517 + deviceInfo + " with reply " + reply);
Kim JeongWoo8b03bc52018-08-10 16:50:23 +0900518 }
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700519 return reply;
520 }
521
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200522
Yuta HIGUCHI371667d2017-09-05 17:30:51 -0700523 // FIXME rename to align with what it actually do
Andrea Campanella3a361452019-08-02 10:17:53 +0200524
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200525 /**
526 * Validate and format netconf message.
Yuta HIGUCHI371667d2017-09-05 17:30:51 -0700527 * - NC1.0 if no EOM sequence present on {@code message}, append.
528 * - NC1.1 chunk-encode given message unless it already is chunk encoded
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200529 *
530 * @param message to format
531 * @return formated message
532 */
533 private String formatNetconfMessage(String message) {
534 if (deviceCapabilities.contains(NETCONF_11_CAPABILITY)) {
535 message = formatChunkedMessage(message);
536 } else {
Yuta HIGUCHI371667d2017-09-05 17:30:51 -0700537 if (!message.endsWith(ENDPATTERN)) {
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200538 message = message + NEW_LINE + ENDPATTERN;
539 }
540 }
Yuta HIGUCHI371667d2017-09-05 17:30:51 -0700541 return message;
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200542 }
543
544 /**
545 * Validate and format message according to chunked framing mechanism.
546 *
547 * @param message to format
548 * @return formated message
549 */
550 private String formatChunkedMessage(String message) {
551 if (message.endsWith(ENDPATTERN)) {
Yuta HIGUCHIb2d05242017-09-05 15:44:34 -0700552 // message given had Netconf 1.0 EOM pattern -> remove
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200553 message = message.substring(0, message.length() - ENDPATTERN.length());
554 }
555 if (!message.startsWith(LF + HASH)) {
Yuta HIGUCHIb2d05242017-09-05 15:44:34 -0700556 // chunk encode message
Yuta HIGUCHI15677982017-08-16 15:50:29 -0700557 message = LF + HASH + message.getBytes(UTF_8).length + LF + message + LF + HASH + HASH + LF;
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200558 }
559 return message;
560 }
561
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700562 @Override
563 @Deprecated
564 public CompletableFuture<String> request(String request) {
565 return streamHandler.sendMessage(request);
566 }
567
Yuta HIGUCHI6e6c26e2017-09-06 14:25:57 -0700568 /**
569 * {@inheritDoc}
570 * <p>
571 * FIXME Note: as of 1.12.0
572 * {@code request} must not include message-id, this method will assign
573 * and insert message-id on it's own.
574 * Will require ONOS-7019 to remove this limitation.
575 */
576 @Override
577 public CompletableFuture<String> rpc(String request) {
578
579 String rpc = request;
580 // - assign message-id
581 int msgId = messageIdInteger.incrementAndGet();
582 // - re-write request to insert message-id
583 // FIXME avoid using formatRequestMessageId
584 rpc = formatRequestMessageId(rpc, msgId);
585 // - ensure it contains XML header
586 rpc = formatXmlHeader(rpc);
587 // - use chunked framing if talking to NC 1.1 device
588 // FIXME avoid using formatNetconfMessage
589 rpc = formatNetconfMessage(rpc);
590
591 // TODO session liveness check & recovery
592
593 log.debug("Sending {} to {}", rpc, this.deviceInfo.getDeviceId());
594 return streamHandler.sendMessage(rpc, msgId)
Andrea Campanella3a361452019-08-02 10:17:53 +0200595 .handleAsync((reply, t) -> {
596 if (t != null) {
597 // secure transport-layer error
598 // cannot use NetconfException, which is
599 // checked Exception.
600 throw new NetconfTransportException(t);
601 } else {
602 // FIXME avoid using checkReply, error handling is weird
603 if (!checkReply(reply)) {
604 throw new NetconfTransportException("rpc-request not successful with device "
605 + deviceInfo + " with reply " + reply);
Yuta HIGUCHI6e6c26e2017-09-06 14:25:57 -0700606 }
Andrea Campanella3a361452019-08-02 10:17:53 +0200607 return reply;
608 }
609 }, SharedExecutors.getPoolThreadExecutor());
Yuta HIGUCHI6e6c26e2017-09-06 14:25:57 -0700610 }
611
Sean Condon54d82432017-07-26 22:27:25 +0100612 @Override
613 public int timeoutConnectSec() {
614 return connectTimeout;
615 }
616
617 @Override
618 public int timeoutReplySec() {
619 return replyTimeout;
620 }
621
622 @Override
623 public int timeoutIdleSec() {
624 return idleTimeout;
625 }
626
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700627 private CompletableFuture<String> request(String request, int messageId) {
628 return streamHandler.sendMessage(request, messageId);
629 }
630
gyewan.an91d7e7e2019-01-17 15:12:48 +0900631 private String sendRequest(String request, boolean isHello) throws NetconfException {
632 return sendRequest(request, isHello, replyTimeout);
633 }
634
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700635 private String sendRequest(String request) throws NetconfException {
Yuta HIGUCHIb2d05242017-09-05 15:44:34 -0700636 // FIXME probably chunk-encoding too early
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200637 request = formatNetconfMessage(request);
gyewan.an91d7e7e2019-01-17 15:12:48 +0900638 return sendRequest(request, false, replyTimeout);
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700639 }
640
gyewan.an91d7e7e2019-01-17 15:12:48 +0900641 private String sendRequest(String request, int timeout) throws NetconfException {
642 // FIXME probably chunk-encoding too early
643 request = formatNetconfMessage(request);
644 return sendRequest(request, false, timeout);
645 }
646
647 private String sendRequest(String request, boolean isHello, int timeout) throws NetconfException {
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700648 checkAndReestablish();
649 int messageId = -1;
650 if (!isHello) {
651 messageId = messageIdInteger.getAndIncrement();
652 }
Yuta HIGUCHIb2d05242017-09-05 15:44:34 -0700653 // FIXME potentially re-writing chunked encoded String?
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700654 request = formatXmlHeader(request);
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200655 request = formatRequestMessageId(request, messageId);
Yuta HIGUCHI371667d2017-09-05 17:30:51 -0700656 log.debug("Sending request to NETCONF with timeout {} for {}",
Andrea Campanella3a361452019-08-02 10:17:53 +0200657 replyTimeout, deviceInfo.name());
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700658 CompletableFuture<String> futureReply = request(request, messageId);
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700659 String rp;
660 try {
661 rp = futureReply.get(replyTimeout, TimeUnit.SECONDS);
Sean Condon7347de92017-07-21 12:17:25 +0100662 replies.remove(messageId); // Why here???
663 } catch (InterruptedException e) {
664 Thread.currentThread().interrupt();
665 throw new NetconfException("Interrupted waiting for reply for request" + request, e);
666 } catch (TimeoutException e) {
Sean Condon54d82432017-07-26 22:27:25 +0100667 throw new NetconfException("Timed out waiting for reply for request " +
668 request + " after " + replyTimeout + " sec.", e);
Sean Condon7347de92017-07-21 12:17:25 +0100669 } catch (ExecutionException e) {
670 log.warn("Closing session {} for {} due to unexpected Error", sessionID, deviceInfo, e);
DongRyeol Chac29f9072018-11-06 14:05:56 +0900671 stopClient();
Sean Condon7347de92017-07-21 12:17:25 +0100672 NetconfDeviceOutputEvent event = new NetconfDeviceOutputEvent(
673 NetconfDeviceOutputEvent.Type.SESSION_CLOSED,
674 null, "Closed due to unexpected error " + e.getCause(),
675 Optional.of(-1), deviceInfo);
676 publishEvent(event);
677 errorReplies.clear(); // move to cleanUp()?
678 cleanUp();
679
680 throw new NetconfException("Closing session " + sessionID + " for " + deviceInfo +
681 " for request " + request, e);
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700682 }
683 log.debug("Result {} from request {} to device {}", rp, request, deviceInfo);
684 return rp.trim();
685 }
686
687 private String formatRequestMessageId(String request, int messageId) {
688 if (request.contains(MESSAGE_ID_STRING)) {
689 //FIXME if application provides his own counting of messages this fails that count
Yuta HIGUCHI371667d2017-09-05 17:30:51 -0700690 // FIXME assumes message-id is integer. RFC6241 allows anything as long as it is allowed in XML
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700691 request = request.replaceFirst(MESSAGE_ID_STRING + EQUAL + NUMBER_BETWEEN_QUOTES_MATCHER,
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200692 MESSAGE_ID_STRING + EQUAL + "\"" + messageId + "\"");
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700693 } else if (!request.contains(MESSAGE_ID_STRING) && !request.contains(HELLO)) {
694 //FIXME find out a better way to enforce the presence of message-id
695 request = request.replaceFirst(END_OF_RPC_OPEN_TAG, "\" " + MESSAGE_ID_STRING + EQUAL + "\""
696 + messageId + "\"" + ">");
697 }
Yuta HIGUCHI371667d2017-09-05 17:30:51 -0700698 request = updateRequestLength(request);
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200699 return request;
700 }
701
Yuta HIGUCHI371667d2017-09-05 17:30:51 -0700702 private String updateRequestLength(String request) {
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200703 if (request.contains(LF + HASH + HASH + LF)) {
704 int oldLen = Integer.parseInt(request.split(HASH)[1].split(LF)[0]);
705 String rpcWithEnding = request.substring(request.indexOf('<'));
706 String firstBlock = request.split(MSGLEN_REGEX_PATTERN)[1].split(LF + HASH + HASH + LF)[0];
707 int newLen = 0;
Yuta HIGUCHI15677982017-08-16 15:50:29 -0700708 newLen = firstBlock.getBytes(UTF_8).length;
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200709 if (oldLen != newLen) {
710 return LF + HASH + newLen + LF + rpcWithEnding;
711 }
712 }
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700713 return request;
714 }
715
Yuta HIGUCHI371667d2017-09-05 17:30:51 -0700716 /**
717 * Ensures xml start directive/declaration appears in the {@code request}.
Andrea Campanella3a361452019-08-02 10:17:53 +0200718 *
Yuta HIGUCHI371667d2017-09-05 17:30:51 -0700719 * @param request RPC request message
720 * @return XML RPC message
721 */
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700722 private String formatXmlHeader(String request) {
Sean Condon2d647172017-09-19 12:29:13 +0100723 if (!request.contains(XML_HEADER)) {
Yuta HIGUCHI15677982017-08-16 15:50:29 -0700724 //FIXME if application provides his own XML header of different type there is a clash
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200725 if (request.startsWith(LF + HASH)) {
726 request = request.split("<")[0] + XML_HEADER + request.substring(request.split("<")[0].length());
727 } else {
728 request = XML_HEADER + "\n" + request;
729 }
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700730 }
731 return request;
732 }
733
734 @Override
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700735 public String getSessionId() {
736 return sessionID;
737 }
738
739 @Override
740 public Set<String> getDeviceCapabilitiesSet() {
741 return Collections.unmodifiableSet(deviceCapabilities);
742 }
743
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700744 @Override
745 public void setOnosCapabilities(Iterable<String> capabilities) {
746 onosCapabilities = capabilities;
747 }
748
749
750 @Override
751 public void addDeviceOutputListener(NetconfDeviceOutputEventListener listener) {
752 streamHandler.addDeviceEventListener(listener);
753 primaryListeners.add(listener);
754 }
755
756 @Override
757 public void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener) {
758 primaryListeners.remove(listener);
759 streamHandler.removeDeviceEventListener(listener);
760 }
761
Yuta HIGUCHI4f55c672018-06-14 18:10:43 -0700762 @Override
763 protected boolean checkReply(String reply) {
764 // Overridden to record error logs
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700765 if (reply != null) {
766 if (!reply.contains("<rpc-error>")) {
767 log.debug("Device {} sent reply {}", deviceInfo, reply);
768 return true;
769 } else if (reply.contains("<ok/>")
770 || (reply.contains("<rpc-error>")
771 && reply.contains("warning"))) {
Yuta HIGUCHI6e6c26e2017-09-06 14:25:57 -0700772 // FIXME rpc-error with a warning is considered same as Ok??
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700773 log.debug("Device {} sent reply {}", deviceInfo, reply);
774 return true;
775 }
776 }
777 log.warn("Device {} has error in reply {}", deviceInfo, reply);
778 return false;
779 }
780
zhongguo zhao78eab372018-08-27 16:22:39 +0800781 @Override
782 public boolean close() throws NetconfException {
783 try {
DongRyeol Chac29f9072018-11-06 14:05:56 +0900784 if (client != null && (client.isClosed() || client.isClosing())) {
785 return true;
786 }
787
zhongguo zhao78eab372018-08-27 16:22:39 +0800788 return super.close();
789 } catch (IOException ioe) {
790 throw new NetconfException(ioe.getMessage());
791 } finally {
DongRyeol Chac29f9072018-11-06 14:05:56 +0900792 disconnected = true;
793 stopClient();
zhongguo zhao78eab372018-08-27 16:22:39 +0800794 }
795 }
796
Sean Condon7347de92017-07-21 12:17:25 +0100797 protected void publishEvent(NetconfDeviceOutputEvent event) {
798 primaryListeners.forEach(lsnr -> {
799 if (lsnr.isRelevant(event)) {
800 lsnr.event(event);
801 }
802 });
803 }
804
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700805 static class NotificationSession extends NetconfSessionMinaImpl {
806
807 private String notificationFilter;
808
809 NotificationSession(NetconfDeviceInfo deviceInfo)
810 throws NetconfException {
811 super(deviceInfo);
812 }
813
814 @Override
815 protected void startSubscriptionStream(String filterSchema)
816 throws NetconfException {
817
818 notificationFilter = filterSchema;
819 requestSync(createSubscriptionString(filterSchema));
820 }
821
822 @Override
823 public String toString() {
824 return MoreObjects.toStringHelper(getClass())
825 .add("deviceInfo", deviceInfo)
826 .add("sessionID", getSessionId())
827 .add("notificationFilter", notificationFilter)
828 .toString();
829 }
830 }
831
832 /**
833 * Listener attached to child session for notification streaming.
834 * <p>
835 * Forwards all notification event from child session to primary session
836 * listeners.
837 */
838 private final class NotificationForwarder
839 implements NetconfDeviceOutputEventListener {
840
841 @Override
842 public boolean isRelevant(NetconfDeviceOutputEvent event) {
843 return event.type() == Type.DEVICE_NOTIFICATION;
844 }
845
846 @Override
847 public void event(NetconfDeviceOutputEvent event) {
Sean Condon7347de92017-07-21 12:17:25 +0100848 publishEvent(event);
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700849 }
850 }
851
852 public class NetconfSessionDelegateImpl implements NetconfSessionDelegate {
853
854 @Override
855 public void notify(NetconfDeviceOutputEvent event) {
856 Optional<Integer> messageId = event.getMessageID();
857 log.debug("messageID {}, waiting replies messageIDs {}", messageId,
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200858 replies.keySet());
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700859 if (!messageId.isPresent()) {
860 errorReplies.add(event.getMessagePayload());
861 log.error("Device {} sent error reply {}",
Kamil Stasiak9f59f442017-05-02 11:02:24 +0200862 event.getDeviceInfo(), event.getMessagePayload());
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700863 return;
864 }
David K. Bainbridge77d8ca42019-02-01 11:47:29 -0800865 // Remove the message as it has been processed.
866 CompletableFuture<String> completedReply = replies.remove(messageId.get());
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700867 if (completedReply != null) {
868 completedReply.complete(event.getMessagePayload());
869 }
870 }
871 }
872
Yuta HIGUCHI2ee4fba2018-06-12 16:21:06 -0700873 /**
874 * @deprecated in 1.14.0
875 */
876 @Deprecated
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700877 public static class MinaSshNetconfSessionFactory implements NetconfSessionFactory {
878
879 @Override
gyewan.an91d7e7e2019-01-17 15:12:48 +0900880 public NetconfSession createNetconfSession(NetconfDeviceInfo netconfDeviceInfo,
881 NetconfController netconfController) throws NetconfException {
Andrea Campanella7bbe7b12017-05-03 16:03:38 -0700882 return new NetconfSessionMinaImpl(netconfDeviceInfo);
883 }
884 }
Sean Condon54d82432017-07-26 22:27:25 +0100885}