18019db57f26c6a64574e50a5dc498e29944d93e
[honeycomb.git] /
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.infra.distro.netconf
18
19 import com.google.inject.Inject
20 import com.google.inject.name.Named
21 import groovy.transform.ToString
22 import groovy.util.logging.Slf4j
23 import io.fd.honeycomb.infra.distro.ProviderTrait
24 import io.netty.channel.nio.NioEventLoopGroup
25 import io.netty.util.Timer
26 import org.opendaylight.netconf.api.NetconfServerDispatcher
27 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService
28 import org.opendaylight.netconf.impl.NetconfServerDispatcherImpl
29 import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory
30 import org.opendaylight.netconf.impl.SessionIdProvider
31 import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory
32 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory
33
34 import java.util.concurrent.TimeUnit
35 /**
36  * Mirror of org.opendaylight.controller.config.yang.config.netconf.northbound.impl.NetconfServerDispatcherModule
37  */
38 @Slf4j
39 @ToString
40 class NetconfServerDispatcherProvider extends ProviderTrait<NetconfServerDispatcher> {
41
42     // TODO make configurable
43     private static final long CONNECTION_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(20)
44
45     @Inject
46     @Named("netconf-mapper-aggregator")
47     NetconfOperationServiceFactory aggregator
48     @Inject
49     NetconfMonitoringService monitoringService
50     @Inject
51     Timer timer
52     @Inject
53     NioEventLoopGroup nettyThreadgroup
54
55
56     def create() {
57         def netconfOperationProvider = new AggregatedNetconfOperationServiceFactory()
58         netconfOperationProvider.onAddNetconfOperationServiceFactory(aggregator)
59
60         def serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory(
61                 timer, netconfOperationProvider, new SessionIdProvider(), CONNECTION_TIMEOUT_MILLIS, monitoringService);
62         def serverChannelInitializer = new NetconfServerDispatcherImpl.ServerChannelInitializer(
63                 serverNegotiatorFactory);
64
65         new NetconfServerDispatcherImpl(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup)
66     }
67
68 }