2 * Copyright (c) 2017 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.bgp;
19 import static io.fd.honeycomb.infra.distro.data.InmemoryDOMDataBrokerProvider.CONFIG;
20 import static io.fd.honeycomb.infra.distro.data.InmemoryDOMDataBrokerProvider.OPERATIONAL;
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;
39 public final class BgpModule extends PrivateModule {
40 private static final Logger LOG = LoggerFactory.getLogger(BgpModule.class);
42 static final String HONEYCOMB_BGP = "honeycomb-bgp";
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);
52 // Create BGP server instance (initialize eagerly to start BGP)
53 bind(BgpServerProvider.BgpServer.class).toProvider(BgpServerProvider.class).asEagerSingleton();
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);
60 // install configuration module (hidden from HC user):
61 install(new BgpConfigurationModule());
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))
70 // Create inmemory operational data store for HONEYCOMB_BGP
71 bind(InMemoryDOMDataStore.class).annotatedWith(Names.named(OPERATIONAL))
72 .toProvider(new DataStoreProvider(OPERATIONAL, LogicalDatastoreType.OPERATIONAL))
75 // Wrap datastores as DOMDataBroker
76 // TODO make executor service configurable
77 bind(DOMDataBroker.class).toProvider(InmemoryDOMDataBrokerProvider.class).in(Singleton.class);
79 // Wrap DOMDataBroker as BA data broker (required by BgpReaderFactoryProvider)
80 bind(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_BGP)).toProvider(BindingDataBrokerProvider.class)
82 expose(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_BGP));
84 // Create RIB instance
85 bind(RIB.class).toProvider(BgpRIBProvider.class).in(Singleton.class);