2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.netconf.test.tool;
11 import io.netty.util.Timer;
12 import java.net.SocketAddress;
13 import java.util.HashMap;
16 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
17 import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory;
18 import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactoryBuilder;
19 import org.opendaylight.netconf.impl.SessionIdProvider;
20 import org.opendaylight.netconf.mapping.api.NetconfOperationService;
21 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
25 public class TesttoolNegotiationFactory extends NetconfServerSessionNegotiatorFactory {
26 private static final Logger LOG = LoggerFactory.getLogger(TesttoolNegotiationFactory.class);
28 private final Map<SocketAddress, NetconfOperationService> cachedOperationServices = new HashMap<>();
30 public TesttoolNegotiationFactory(final Timer timer, final NetconfOperationServiceFactory netconfOperationProvider,
31 final SessionIdProvider idProvider, final long connectionTimeoutMillis,
32 final NetconfMonitoringService monitoringService) {
33 super(timer, netconfOperationProvider, idProvider, connectionTimeoutMillis, monitoringService, NetconfServerSessionNegotiatorFactory.DEFAULT_BASE_CAPABILITIES);
36 public TesttoolNegotiationFactory(final Timer timer, final NetconfOperationServiceFactory netconfOperationProvider,
37 final SessionIdProvider idProvider, final long connectionTimeoutMillis,
38 final NetconfMonitoringService monitoringService, final Set<String> baseCapabilities) {
39 super(timer, netconfOperationProvider, idProvider, connectionTimeoutMillis, monitoringService, baseCapabilities);
43 protected NetconfOperationService getOperationServiceForAddress(final String netconfSessionIdForReporting, final SocketAddress socketAddress) {
44 if (cachedOperationServices.containsKey(socketAddress)) {
45 LOG.debug("Session {}: Getting cached operation service factory for test tool device on address {}",
46 netconfSessionIdForReporting, socketAddress);
47 return cachedOperationServices.get(socketAddress);
49 final NetconfOperationService service = getOperationServiceFactory().createService(netconfSessionIdForReporting);
50 cachedOperationServices.put(socketAddress, service);
51 LOG.debug("Session {}: Creating new operation service factory for test tool device on address {}",
52 netconfSessionIdForReporting, socketAddress);