HONEYCOMB-21 Vpp-integration minimal distribution
[honeycomb.git] / infra / minimal-distribution / src / main / java / io / fd / honeycomb / infra / distro / netconf / NetconfModule.groovy
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.PrivateModule
20 import com.google.inject.Singleton
21 import com.google.inject.name.Names
22 import io.fd.honeycomb.infra.distro.data.BindingDataBrokerProvider
23 import io.fd.honeycomb.infra.distro.data.DataStoreProvider
24 import io.fd.honeycomb.infra.distro.data.HoneycombNotificationManagerProvider
25 import io.fd.honeycomb.infra.distro.data.InmemoryDOMDataBrokerProvider
26 import io.fd.honeycomb.notification.NotificationCollector
27 import io.netty.channel.nio.NioEventLoopGroup
28 import io.netty.util.Timer
29 import org.opendaylight.controller.md.sal.binding.api.DataBroker
30 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType
31 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker
32 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore
33 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker
34 import org.opendaylight.netconf.api.NetconfServerDispatcher
35 import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService
36 import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory
37 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory
38 import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactoryListener
39 import org.opendaylight.netconf.notifications.NetconfNotificationCollector
40 import org.opendaylight.netconf.notifications.NetconfNotificationListener
41 import org.opendaylight.netconf.notifications.NetconfNotificationRegistry
42 import org.opendaylight.netconf.notifications.impl.NetconfNotificationManager
43
44 import static InmemoryDOMDataBrokerProvider.CONFIG
45 import static InmemoryDOMDataBrokerProvider.OPERATIONAL
46
47 class NetconfModule extends PrivateModule {
48
49     @Override
50     protected void configure() {
51         bind(InMemoryDOMDataStore)
52                 .annotatedWith(Names.named(CONFIG))
53                 .toProvider(new DataStoreProvider(type: LogicalDatastoreType.CONFIGURATION, name: CONFIG))
54                 .in(Singleton)
55         bind(InMemoryDOMDataStore)
56                 .annotatedWith(Names.named(OPERATIONAL))
57                 .toProvider(new DataStoreProvider(type: LogicalDatastoreType.OPERATIONAL, name: OPERATIONAL))
58                 .in(Singleton)
59         bind(DOMDataBroker).toProvider(InmemoryDOMDataBrokerProvider).in(Singleton)
60
61         bind(DataBroker)
62                 .annotatedWith(Names.named("netconf"))
63                 .toProvider(BindingDataBrokerProvider)
64                 .in(Singleton)
65         expose(DataBroker).annotatedWith(Names.named("netconf"))
66         bind(BindingAwareBroker)
67                 .annotatedWith(Names.named("netconf"))
68                 .toProvider(NetconfBindingBrokerProvider)
69                 .in(Singleton)
70
71         // Mirror of org.opendaylight.controller.config.yang.config.netconf.northbound.impl.NetconfMapperAggregatorModule
72         def factory = new AggregatedNetconfOperationServiceFactory()
73         bind(NetconfOperationServiceFactory)
74                 .annotatedWith(Names.named("netconf-mapper-aggregator"))
75                 .toInstance(factory)
76         bind(NetconfOperationServiceFactoryListener).toInstance(factory)
77
78         // Mirror of org.opendaylight.controller.config.yang.netconf.northbound.notification.impl.NetconfNotificationManagerModule
79         def manager = new NetconfNotificationManager()
80         bind(NetconfNotificationCollector).toInstance(manager)
81         bind(NetconfNotificationRegistry).toInstance(manager)
82         bind(NetconfNotificationListener).toInstance(manager)
83
84         // Netconf notification part
85         bind(NetconfOperationServiceFactory)
86                 .annotatedWith(Names.named("netconf-mapper-notification"))
87                 .toProvider(NetconfNotificationMapperProvider)
88                 .in(Singleton)
89         expose(NetconfOperationServiceFactory).annotatedWith(Names.named("netconf-mapper-notification"))
90
91         // Netconf core part - mapping between Honeycomb and Netconf
92         bind(NetconfOperationServiceFactory)
93                 .annotatedWith(Names.named("netconf-mapper-honeycomb"))
94                 .toProvider(NetconfMdsalMapperProvider)
95                 .in(Singleton)
96         expose(NetconfOperationServiceFactory).annotatedWith(Names.named("netconf-mapper-honeycomb"))
97
98         // Netconf monitoring part
99         bind(NetconfMonitoringService).toProvider(NetconfMonitoringServiceProvider).in(Singleton)
100         bind(NetconfOperationServiceFactory)
101                 .annotatedWith(Names.named("netconf-mapper-monitoring"))
102                 .toProvider(NetconfMonitoringMapperProvider)
103                 .in(Singleton)
104         expose(NetconfOperationServiceFactory).annotatedWith(Names.named("netconf-mapper-monitoring"))
105
106         bind(NotificationCollector).toProvider(HoneycombNotificationManagerProvider).in(Singleton)
107         bind(HoneycombNotification2NetconfProvider.HoneycombNotification2Netconf)
108                 .toProvider(HoneycombNotification2NetconfProvider)
109                 .in(Singleton)
110         expose(HoneycombNotification2NetconfProvider.HoneycombNotification2Netconf)
111
112         configureServer()
113     }
114
115     def configureServer() {
116         bind(NioEventLoopGroup).toProvider(NettyThreadGroupProvider).in(Singleton)
117         bind(Timer).toProvider(NettyTimerProvider).in(Singleton)
118         bind(NetconfServerDispatcher).toProvider(NetconfServerDispatcherProvider).in(Singleton)
119         bind(NetconfTcpServerProvider.NetconfTcpServer).toProvider(NetconfTcpServerProvider).in(Singleton)
120         expose(NetconfTcpServerProvider.NetconfTcpServer)
121         bind(NetconfSshServerProvider.NetconfSshServer).toProvider(NetconfSshServerProvider).in(Singleton)
122         expose(NetconfSshServerProvider.NetconfSshServer)
123     }
124 }