Integrate netconf-mapping-api into netconf-server
[netconf.git] / netconf / tools / netconf-testtool / src / main / java / org / opendaylight / netconf / test / tool / TesttoolNegotiationFactory.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.netconf.test.tool;
10
11 import io.netty.util.Timer;
12 import java.net.SocketAddress;
13 import java.util.HashMap;
14 import java.util.Map;
15 import java.util.Set;
16 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
17 import org.opendaylight.netconf.server.NetconfServerSessionNegotiatorFactory;
18 import org.opendaylight.netconf.server.api.SessionIdProvider;
19 import org.opendaylight.netconf.server.api.operations.NetconfOperationService;
20 import org.opendaylight.netconf.server.api.operations.NetconfOperationServiceFactory;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 public class TesttoolNegotiationFactory extends NetconfServerSessionNegotiatorFactory {
25     private static final Logger LOG = LoggerFactory.getLogger(TesttoolNegotiationFactory.class);
26
27     private final Map<SocketAddress, NetconfOperationService> cachedOperationServices = new HashMap<>();
28
29     public TesttoolNegotiationFactory(final Timer timer, final NetconfOperationServiceFactory netconfOperationProvider,
30             final SessionIdProvider idProvider, final long connectionTimeoutMillis,
31             final NetconfMonitoringService monitoringService) {
32         super(timer, netconfOperationProvider, idProvider, connectionTimeoutMillis, monitoringService,
33             NetconfServerSessionNegotiatorFactory.DEFAULT_BASE_CAPABILITIES);
34     }
35
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,
40             monitoringService, baseCapabilities);
41     }
42
43     @Override
44     protected NetconfOperationService getOperationServiceForAddress(
45             final String netconfSessionIdForReporting, final SocketAddress socketAddress) {
46         if (cachedOperationServices.containsKey(socketAddress)) {
47             LOG.debug("Session {}: Getting cached operation service factory for test tool device on address {}",
48                     netconfSessionIdForReporting, socketAddress);
49             return cachedOperationServices.get(socketAddress);
50         } else {
51             final NetconfOperationService service = getOperationServiceFactory()
52                 .createService(netconfSessionIdForReporting);
53             cachedOperationServices.put(socketAddress, service);
54             LOG.debug("Session {}: Creating new operation service factory for test tool device on address {}",
55                     netconfSessionIdForReporting, socketAddress);
56             return service;
57         }
58     }
59 }