Honeynode test tool
[transportpce.git] / tests / honeynode / netconf / src / main / java / io / fd / honeycomb / northbound / netconf / NetconfServerDispatcherProvider.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
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
17 package io.fd.honeycomb.northbound.netconf;
18
19 import com.google.inject.Inject;
20 import com.google.inject.name.Named;
21 import io.fd.honeycomb.binding.init.ProviderTrait;
22 import io.netty.channel.nio.NioEventLoopGroup;
23 import io.netty.util.Timer;
24 import java.util.concurrent.TimeUnit;
25 import org.opendaylight.netconf.api.NetconfServerDispatcher;
26 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService;
27 import org.opendaylight.netconf.impl.NetconfServerDispatcherImpl;
28 import org.opendaylight.netconf.impl.SessionIdProvider;
29 import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory;
30 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory;
31
32 public final class NetconfServerDispatcherProvider extends ProviderTrait<NetconfServerDispatcher> {
33     private static final long CONNECTION_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(20);
34
35     @Inject
36     @Named(NetconfModule.HONEYCOMB_NETCONF_MAPPER_AGGR)
37     private NetconfOperationServiceFactory aggregator;
38     @Inject
39     private NetconfMonitoringService monitoringService;
40     @Inject
41     private Timer timer;
42     @Inject
43     private NioEventLoopGroup nettyThreadgroup;
44
45     @Override
46     protected NetconfServerDispatcherImpl create() {
47         AggregatedNetconfOperationServiceFactory netconfOperationProvider =
48                 new AggregatedNetconfOperationServiceFactory();
49         netconfOperationProvider.onAddNetconfOperationServiceFactory(aggregator);
50
51         NetconfServerSessionNegotiatorFactory serverNegotiatorFactory =
52                 new NetconfServerSessionNegotiatorFactory(timer, netconfOperationProvider, new SessionIdProvider(),
53                         CONNECTION_TIMEOUT_MILLIS, monitoringService);
54         NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer =
55                 new NetconfServerDispatcherImpl.ServerChannelInitializer(serverNegotiatorFactory);
56
57         return new NetconfServerDispatcherImpl(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup);
58     }
59
60     private static final class NetconfServerSessionNegotiatorFactory extends
61             org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory {
62
63         NetconfServerSessionNegotiatorFactory(final Timer timer,
64                                                      final AggregatedNetconfOperationServiceFactory netconfOperationProvider,
65                                                      final SessionIdProvider sessionIdProvider,
66                                                      final long connectionTimeoutMillis,
67                                                      final NetconfMonitoringService monitoringService) {
68             super(timer, netconfOperationProvider, sessionIdProvider, connectionTimeoutMillis, monitoringService,
69                     org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory.DEFAULT_BASE_CAPABILITIES);
70         }
71     }
72 }