2 * Copyright (c) 2016 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.infra.distro.netconf
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
44 import static InmemoryDOMDataBrokerProvider.CONFIG
45 import static InmemoryDOMDataBrokerProvider.OPERATIONAL
47 class NetconfModule extends PrivateModule {
49 public static final String NETCONF = "netconf"
50 public static final String NETCONF_MAPPER_AGGREGATOR = "netconf-mapper-aggregator"
51 public static final String NETCONF_MAPPER_NOTIFICATION = "netconf-mapper-notification"
52 public static final String NETCONF_MAPPER_MONITORING = "netconf-mapper-monitoring"
53 public static final String NETCONF_MAPPER_HONEYCOMB = "netconf-mapper-honeycomb"
56 protected void configure() {
57 bind(InMemoryDOMDataStore)
58 .annotatedWith(Names.named(CONFIG))
59 .toProvider(new DataStoreProvider(type: LogicalDatastoreType.CONFIGURATION, name: CONFIG))
61 bind(InMemoryDOMDataStore)
62 .annotatedWith(Names.named(OPERATIONAL))
63 .toProvider(new DataStoreProvider(type: LogicalDatastoreType.OPERATIONAL, name: OPERATIONAL))
65 bind(DOMDataBroker).toProvider(InmemoryDOMDataBrokerProvider).in(Singleton)
68 .annotatedWith(Names.named(NETCONF))
69 .toProvider(BindingDataBrokerProvider)
71 expose(DataBroker).annotatedWith(Names.named(NETCONF))
72 bind(BindingAwareBroker)
73 .annotatedWith(Names.named(NETCONF))
74 .toProvider(NetconfBindingBrokerProvider)
77 // Mirror of org.opendaylight.controller.config.yang.config.netconf.northbound.impl.NetconfMapperAggregatorModule
78 def factory = new AggregatedNetconfOperationServiceFactory()
79 bind(NetconfOperationServiceFactory)
80 .annotatedWith(Names.named(NETCONF_MAPPER_AGGREGATOR))
82 bind(NetconfOperationServiceFactoryListener).toInstance(factory)
84 // Mirror of org.opendaylight.controller.config.yang.netconf.northbound.notification.impl.NetconfNotificationManagerModule
85 def manager = new NetconfNotificationManager()
86 bind(NetconfNotificationCollector).toInstance(manager)
87 bind(NetconfNotificationRegistry).toInstance(manager)
88 bind(NetconfNotificationListener).toInstance(manager)
90 // Netconf notification part
91 bind(NetconfOperationServiceFactory)
92 .annotatedWith(Names.named(NETCONF_MAPPER_NOTIFICATION))
93 .toProvider(NetconfNotificationMapperProvider)
95 expose(NetconfOperationServiceFactory).annotatedWith(Names.named(NETCONF_MAPPER_NOTIFICATION))
97 // Netconf core part - mapping between Honeycomb and Netconf
98 bind(NetconfOperationServiceFactory)
99 .annotatedWith(Names.named(NETCONF_MAPPER_HONEYCOMB))
100 .toProvider(NetconfMdsalMapperProvider)
102 expose(NetconfOperationServiceFactory).annotatedWith(Names.named(NETCONF_MAPPER_HONEYCOMB))
104 // Netconf monitoring part
105 bind(NetconfMonitoringService).toProvider(NetconfMonitoringServiceProvider).in(Singleton)
106 bind(NetconfOperationServiceFactory)
107 .annotatedWith(Names.named(NETCONF_MAPPER_MONITORING))
108 .toProvider(NetconfMonitoringMapperProvider)
110 expose(NetconfOperationServiceFactory).annotatedWith(Names.named(NETCONF_MAPPER_MONITORING))
112 bind(NotificationCollector).toProvider(HoneycombNotificationManagerProvider).in(Singleton)
113 bind(HoneycombNotification2NetconfProvider.HoneycombNotification2Netconf)
114 .toProvider(HoneycombNotification2NetconfProvider)
116 expose(HoneycombNotification2NetconfProvider.HoneycombNotification2Netconf)
121 def configureServer() {
122 bind(NioEventLoopGroup).toProvider(NettyThreadGroupProvider).in(Singleton)
123 bind(Timer).toProvider(NettyTimerProvider).in(Singleton)
124 bind(NetconfServerDispatcher).toProvider(NetconfServerDispatcherProvider).in(Singleton)
125 bind(NetconfTcpServerProvider.NetconfTcpServer).toProvider(NetconfTcpServerProvider).in(Singleton)
126 expose(NetconfTcpServerProvider.NetconfTcpServer)
127 bind(NetconfSshServerProvider.NetconfSshServer).toProvider(NetconfSshServerProvider).in(Singleton)
128 expose(NetconfSshServerProvider.NetconfSshServer)