Dedicated provider for BgpNeighbours 54/6954/1
authorMarek Gradzki <mgradzki@cisco.com>
Wed, 31 May 2017 08:50:13 +0000 (10:50 +0200)
committerMarek Gradzki <mgradzki@cisco.com>
Wed, 31 May 2017 08:50:13 +0000 (10:50 +0200)
Change-Id: I1a98ea27dde5ba77f8b20382dfeb29496f3282b2
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
infra/bgp-distribution/src/main/java/io/fd/honeycomb/infra/bgp/BgpModule.java
infra/bgp-distribution/src/main/java/io/fd/honeycomb/infra/bgp/BgpNeighboursProvider.java [moved from infra/bgp-distribution/src/main/java/io/fd/honeycomb/infra/bgp/BGPPeerRegistryProvider.java with 93% similarity]
infra/bgp-distribution/src/main/java/io/fd/honeycomb/infra/bgp/distro/Main.java

index 128e9f0..efef5a7 100644 (file)
@@ -32,9 +32,11 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
 import org.opendaylight.protocol.bgp.openconfig.impl.BGPOpenConfigMappingServiceImpl;
 import org.opendaylight.protocol.bgp.openconfig.spi.BGPOpenConfigMappingService;
+import org.opendaylight.protocol.bgp.rib.impl.StrictBGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.BgpNeighbors;
 
 public final class BgpModule extends PrivateModule {
 
@@ -49,11 +51,16 @@ public final class BgpModule extends PrivateModule {
 
         // Configure peer registry
         bind(BGPOpenConfigMappingService.class).toInstance(new BGPOpenConfigMappingServiceImpl());
-        bind(BGPPeerRegistry.class).toProvider(BGPPeerRegistryProvider.class);
+        bind(BGPPeerRegistry.class).toInstance(StrictBGPPeerRegistry.instance());
+
 
         // Create BGP server instance
         bind(BgpServerProvider.BgpServer.class).toProvider(BgpServerProvider.class).in(Singleton.class);
         expose(BgpServerProvider.BgpServer.class);
+
+        // Initialize BgpNeighbours
+        bind(BgpNeighbors.class).toProvider(BgpNeighboursProvider.class).in(Singleton.class);
+        expose(BgpNeighbors.class);
     }
 
     private void configureRIB() {
@@ -37,6 +37,7 @@ import org.opendaylight.protocol.bgp.rib.impl.config.BgpPeer;
 import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
 import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.BgpNeighborPeerGroupConfig;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.BgpNeighbors;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbors.Neighbor;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp;
 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Neighbors;
@@ -60,8 +61,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-final class BGPPeerRegistryProvider extends ProviderTrait<BGPPeerRegistry> {
-    private static final Logger LOG = LoggerFactory.getLogger(BGPPeerRegistryProvider.class);
+final class BgpNeighboursProvider extends ProviderTrait<BgpNeighbors> {
+    private static final Logger LOG = LoggerFactory.getLogger(BgpNeighboursProvider.class);
     private static final String PEERS_CFG = "/bgp-peers.json";
     @Inject
     private BindingToNormalizedNodeCodec codec;
@@ -71,11 +72,12 @@ final class BGPPeerRegistryProvider extends ProviderTrait<BGPPeerRegistry> {
     private BGPOpenConfigMappingService mappingService;
     @Inject
     private SchemaService schemaService;
+    @Inject
+    private BGPPeerRegistry peerRegistry;
 
     @Override
-    protected BGPPeerRegistry create() {
-        final BGPPeerRegistry peerRegistry = StrictBGPPeerRegistry.instance();
-        final Neighbors neighbors = readNeighbours();
+    protected BgpNeighbors create() {
+        final BgpNeighbors neighbors = readNeighbours();
         for (final Neighbor neighbor : neighbors.getNeighbor()) {
             if (isApplicationPeer(neighbor)) {
                 LOG.trace("Starting AppPeer for {}", neighbor);
@@ -85,8 +87,8 @@ final class BGPPeerRegistryProvider extends ProviderTrait<BGPPeerRegistry> {
                 new BgpPeer(null, peerRegistry).start(globalRib, neighbor, mappingService, null);
             }
         }
-        LOG.debug("Created BGPPeerRegistry with neighbours {}", neighbors);
-        return peerRegistry;
+        LOG.debug("BgpNeighbours initialized: {}", neighbors);
+        return neighbors;
     }
 
     private Neighbors readNeighbours() {
index 0204e1f..bf6725a 100644 (file)
@@ -28,6 +28,7 @@ import com.google.inject.ProvisionException;
 import io.fd.honeycomb.infra.bgp.BgpConfiguration;
 import io.fd.honeycomb.infra.bgp.BgpServerProvider;
 import java.util.Set;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.BgpNeighbors;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -54,6 +55,8 @@ public final class Main {
             if (bgpAttributes.isBgpEnabled()) {
                 LOG.info("Starting BGP");
                 injector.getInstance(BgpServerProvider.BgpServer.class);
+                LOG.info("Initializing BgpNeighbours");
+                injector.getInstance(BgpNeighbors.class);
                 LOG.info("BGP started successfully!");
             }