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
8 package org.opendaylight.netconf.test.tool;
10 import io.netty.util.Timer;
11 import java.net.SocketAddress;
12 import java.util.HashMap;
15 import org.opendaylight.netconf.server.NetconfServerSessionNegotiatorFactory;
16 import org.opendaylight.netconf.server.api.SessionIdProvider;
17 import org.opendaylight.netconf.server.api.monitoring.NetconfMonitoringService;
18 import org.opendaylight.netconf.server.api.operations.NetconfOperationService;
19 import org.opendaylight.netconf.server.api.operations.NetconfOperationServiceFactory;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class TesttoolNegotiationFactory extends NetconfServerSessionNegotiatorFactory {
24 private static final Logger LOG = LoggerFactory.getLogger(TesttoolNegotiationFactory.class);
26 private final Map<SocketAddress, NetconfOperationService> cachedOperationServices = new HashMap<>();
28 public TesttoolNegotiationFactory(final Timer timer, final NetconfOperationServiceFactory netconfOperationProvider,
29 final SessionIdProvider idProvider, final long connectionTimeoutMillis,
30 final NetconfMonitoringService monitoringService) {
31 super(timer, netconfOperationProvider, idProvider, connectionTimeoutMillis, monitoringService,
32 NetconfServerSessionNegotiatorFactory.DEFAULT_BASE_CAPABILITIES);
35 public TesttoolNegotiationFactory(final Timer timer, final NetconfOperationServiceFactory netconfOperationProvider,
36 final SessionIdProvider idProvider, final long connectionTimeoutMillis,
37 final NetconfMonitoringService monitoringService, final Set<String> baseCapabilities) {
38 super(timer, netconfOperationProvider, idProvider, connectionTimeoutMillis,
39 monitoringService, baseCapabilities);
43 protected NetconfOperationService getOperationServiceForAddress(
44 final String netconfSessionIdForReporting, final SocketAddress socketAddress) {
45 if (cachedOperationServices.containsKey(socketAddress)) {
46 LOG.debug("Session {}: Getting cached operation service factory for test tool device on address {}",
47 netconfSessionIdForReporting, socketAddress);
48 return cachedOperationServices.get(socketAddress);
50 final NetconfOperationService service = getOperationServiceFactory()
51 .createService(netconfSessionIdForReporting);
52 cachedOperationServices.put(socketAddress, service);
53 LOG.debug("Session {}: Creating new operation service factory for test tool device on address {}",
54 netconfSessionIdForReporting, socketAddress);