HONEYCOMB-362: bump ODL dependencies to Carbon
[honeycomb.git] / infra / northbound / bgp / src / main / java / io / fd / honeycomb / infra / bgp / BgpModule.java
1 /*
2  * Copyright (c) 2017 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.bgp;
18
19 import static io.fd.honeycomb.infra.distro.data.InmemoryDOMDataBrokerProvider.CONFIG;
20 import static io.fd.honeycomb.infra.distro.data.InmemoryDOMDataBrokerProvider.OPERATIONAL;
21
22 import com.google.inject.PrivateModule;
23 import com.google.inject.Singleton;
24 import com.google.inject.name.Names;
25 import io.fd.honeycomb.infra.distro.data.BindingDataBrokerProvider;
26 import io.fd.honeycomb.infra.distro.data.DataStoreProvider;
27 import io.fd.honeycomb.infra.distro.data.InmemoryDOMDataBrokerProvider;
28 import io.fd.honeycomb.translate.bgp.RibWriter;
29 import io.netty.channel.EventLoopGroup;
30 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
31 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
32 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
33 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
34 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
35 import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38
39 public final class BgpModule extends PrivateModule {
40     private static final Logger LOG = LoggerFactory.getLogger(BgpModule.class);
41
42     static final String HONEYCOMB_BGP = "honeycomb-bgp";
43
44     protected void configure() {
45         LOG.debug("Initializing BgpModule");
46         // Create BGPDispatcher BGPDispatcher for creating BGP clients
47         bind(EventLoopGroup.class).toProvider(BgpNettyThreadGroupProvider.class).in(Singleton.class);
48         bind(BGPDispatcher.class).toProvider(BGPDispatcherImplProvider.class).in(Singleton.class);
49
50         configureRIB();
51
52         // Create BGP server instance (initialize eagerly to start BGP)
53         bind(BgpServerProvider.BgpServer.class).toProvider(BgpServerProvider.class).asEagerSingleton();
54
55         // Listens for local RIB modifications and passes routes to translation layer
56         // (initialize eagerly to configure RouteWriters)
57         bind(RibWriter.class).toProvider(LocRibWriterProvider.class).asEagerSingleton();
58         expose(RibWriter.class);
59
60         // install configuration module (hidden from HC user):
61         install(new BgpConfigurationModule());
62     }
63
64     private void configureRIB() {
65         // Create inmemory config data store for HONEYCOMB_BGP
66         bind(InMemoryDOMDataStore.class).annotatedWith(Names.named(CONFIG))
67             .toProvider(new DataStoreProvider(CONFIG, LogicalDatastoreType.CONFIGURATION))
68             .in(Singleton.class);
69
70         // Create inmemory operational data store for HONEYCOMB_BGP
71         bind(InMemoryDOMDataStore.class).annotatedWith(Names.named(OPERATIONAL))
72             .toProvider(new DataStoreProvider(OPERATIONAL, LogicalDatastoreType.OPERATIONAL))
73             .in(Singleton.class);
74
75         // Wrap datastores as DOMDataBroker
76         // TODO make executor service configurable
77         bind(DOMDataBroker.class).toProvider(InmemoryDOMDataBrokerProvider.class).in(Singleton.class);
78
79         // Wrap DOMDataBroker as BA data broker (required by BgpReaderFactoryProvider)
80         bind(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_BGP)).toProvider(BindingDataBrokerProvider.class)
81             .in(Singleton.class);
82         expose(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_BGP));
83
84         // Create RIB instance
85         bind(RIB.class).toProvider(BgpRIBProvider.class).in(Singleton.class);
86         expose(RIB.class);
87     }
88 }