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.netty.channel.EventLoopGroup;
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.protocol.bgp.openconfig.impl.BGPOpenConfigMappingServiceImpl;
34 import org.opendaylight.protocol.bgp.openconfig.spi.BGPOpenConfigMappingService;
35 import org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry;
36 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
37 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
38 import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
39 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.BgpNeighbors;
41 public final class BgpModule extends PrivateModule {
43 static final String HONEYCOMB_BGP = "honeycomb-bgp";
45 protected void configure() {
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 // Configure peer registry
53 bind(BGPOpenConfigMappingService.class).toInstance(new BGPOpenConfigMappingServiceImpl());
54 bind(BGPPeerRegistry.class).toInstance(StrictBGPPeerRegistry.instance());
57 // Create BGP server instance
58 bind(BgpServerProvider.BgpServer.class).toProvider(BgpServerProvider.class).in(Singleton.class);
59 expose(BgpServerProvider.BgpServer.class);
61 // Initialize BgpNeighbours
62 bind(BgpNeighbors.class).toProvider(BgpNeighboursProvider.class).in(Singleton.class);
63 expose(BgpNeighbors.class);
66 private void configureRIB() {
67 // Create inmemory config data store for HONEYCOMB_BGP
68 bind(InMemoryDOMDataStore.class).annotatedWith(Names.named(CONFIG))
69 .toProvider(new DataStoreProvider(CONFIG, LogicalDatastoreType.CONFIGURATION))
72 // Create inmemory operational data store for HONEYCOMB_BGP
73 bind(InMemoryDOMDataStore.class).annotatedWith(Names.named(OPERATIONAL))
74 .toProvider(new DataStoreProvider(OPERATIONAL, LogicalDatastoreType.OPERATIONAL))
77 // Wrap datastores as DOMDataBroker
78 // TODO make executor service configurable
79 bind(DOMDataBroker.class).toProvider(InmemoryDOMDataBrokerProvider.class).in(Singleton.class);
81 // Wrap DOMDataBroker as BA data broker (required by BgpReaderFactoryProvider)
82 bind(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_BGP)).toProvider(BindingDataBrokerProvider.class)
84 expose(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_BGP));
86 // Create RIB instance
87 bind(RIB.class).toProvider(BgpRIBProvider.class).in(Singleton.class);