summaryrefslogtreecommitdiffstats
path: root/infra/northbound/bgp/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'infra/northbound/bgp/src/main')
-rw-r--r--infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/ApplicationRibWriterFactory.java4
-rw-r--r--infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpConfiguration.java17
-rw-r--r--infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpModule.java2
-rw-r--r--infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpPolicyConfiguration.java70
-rw-r--r--infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpPolicyConfigurationModule.java34
-rw-r--r--infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpRIBProvider.java85
-rw-r--r--infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpReaderFactoryProvider.java4
-rw-r--r--infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/neighbors/BgpPeerWriterFactory.java10
-rw-r--r--infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/neighbors/NeighborCustomizer.java40
-rw-r--r--infra/northbound/bgp/src/main/resources/honeycomb-minimal-resources/config/bgp-policy.json4
10 files changed, 212 insertions, 58 deletions
diff --git a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/ApplicationRibWriterFactory.java b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/ApplicationRibWriterFactory.java
index 05a2a9602..9ff55207b 100644
--- a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/ApplicationRibWriterFactory.java
+++ b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/ApplicationRibWriterFactory.java
@@ -23,8 +23,8 @@ import io.fd.honeycomb.translate.util.write.BindingBrokerWriter;
import io.fd.honeycomb.translate.write.WriterFactory;
import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.ApplicationRib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.Tables;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.ApplicationRib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.Tables;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
diff --git a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpConfiguration.java b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpConfiguration.java
index b651c4c0a..2c6c17c92 100644
--- a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpConfiguration.java
+++ b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpConfiguration.java
@@ -18,9 +18,17 @@ package io.fd.honeycomb.infra.bgp;
import com.google.common.base.MoreObjects;
import java.util.Optional;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import net.jmob.guice.conf.core.BindConfig;
import net.jmob.guice.conf.core.InjectConfig;
import net.jmob.guice.conf.core.Syntax;
+import org.opendaylight.protocol.bgp.rib.impl.config.PeerGroupConfigLoader;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.peer.group.PeerGroup;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.peer.group.PeerGroupBuilder;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.Bgp;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
/**
* This is the Java equivalent for bgp.json file. We use guice-config library to load all the config attributes into
@@ -29,7 +37,7 @@ import net.jmob.guice.conf.core.Syntax;
* The BindConfig annotation tells that bgp.json file should be looked up on classpath root.
*/
@BindConfig(value = "bgp", syntax = Syntax.JSON)
-public class BgpConfiguration {
+public class BgpConfiguration implements PeerGroupConfigLoader {
@InjectConfig("bgp-binding-address")
public Optional<String> bgpBindingAddress;
@@ -65,4 +73,11 @@ public class BgpConfiguration {
.add("bgpNettyThreads", bgpNettyThreads)
.toString();
}
+
+ @Nullable
+ @Override
+ public PeerGroup getPeerGroup(@Nonnull final InstanceIdentifier<Bgp> instanceIdentifier,
+ @Nonnull final String neighbor) {
+ return new PeerGroupBuilder().setConfig(new ConfigBuilder().build()).build();
+ }
}
diff --git a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpModule.java b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpModule.java
index 6aab7c6ca..7123caf14 100644
--- a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpModule.java
+++ b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpModule.java
@@ -47,6 +47,8 @@ public final class BgpModule extends PrivateModule {
// Create BGPDispatcher BGPDispatcher for creating BGP clients
bind(EventLoopGroup.class).toProvider(BgpNettyThreadGroupProvider.class).in(Singleton.class);
bind(BGPDispatcher.class).toProvider(BGPDispatcherImplProvider.class).in(Singleton.class);
+ // Bind BgpPolicy configuration before RIB is initialized
+ install(new BgpPolicyConfigurationModule());
configureRIB();
diff --git a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpPolicyConfiguration.java b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpPolicyConfiguration.java
new file mode 100644
index 000000000..911cbfd86
--- /dev/null
+++ b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpPolicyConfiguration.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2018 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.infra.bgp;
+
+import com.google.common.base.MoreObjects;
+import java.util.Collections;
+import java.util.Optional;
+import net.jmob.guice.conf.core.BindConfig;
+import net.jmob.guice.conf.core.InjectConfig;
+import net.jmob.guice.conf.core.Syntax;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.DefaultPolicyType;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.apply.policy.group.apply.policy.Config;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.apply.policy.group.apply.policy.ConfigBuilder;
+
+/**
+ * This is the Java equivalent for bgp-policy.json file. We use guice-config library to load all the config attributes
+ * into this class instance.
+ *
+ * The BindConfig annotation tells that bgp-policy.json file should be looked up on classpath root.
+ *
+ * For now we support only default actions for import and export policies (ACCEPT-ROUTE or REJECT-ROUTE)
+ */
+
+// TODO (HONEYCOMB-446) Add full support of initial configuration for BGP policy.
+@BindConfig(value = "bgp-policy", syntax = Syntax.JSON)
+public class BgpPolicyConfiguration {
+
+ @InjectConfig("default-import-policy")
+ public Optional<String> defaultImportPolicy;
+ @InjectConfig("default-export-policy")
+ public Optional<String> defaultExportPolicy;
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("default-import-policy", defaultImportPolicy)
+ .add("default-export-policy", defaultExportPolicy)
+ .toString();
+ }
+
+ public Optional<Config> getPolicyConfig() {
+ if (defaultImportPolicy.isPresent() && defaultExportPolicy.isPresent()) {
+ Config config = new ConfigBuilder()
+ .setDefaultImportPolicy(
+ DefaultPolicyType.valueOf(defaultImportPolicy.get().replace("-", "")))
+ .setDefaultExportPolicy(
+ DefaultPolicyType.valueOf(defaultExportPolicy.get().replace("-", "")))
+ .setImportPolicy(Collections.emptyList())
+ .setExportPolicy(Collections.emptyList())
+ .build();
+ return Optional.of(config);
+ } else {
+ return Optional.empty();
+ }
+ }
+}
diff --git a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpPolicyConfigurationModule.java b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpPolicyConfigurationModule.java
new file mode 100644
index 000000000..3137150c3
--- /dev/null
+++ b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpPolicyConfigurationModule.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2018 Cisco and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.fd.honeycomb.infra.bgp;
+
+import com.google.inject.AbstractModule;
+import net.jmob.guice.conf.core.ConfigurationModule;
+
+/**
+ * Load the configuration from json into HoneycombConfiguration and make it available.
+ */
+final class BgpPolicyConfigurationModule extends AbstractModule {
+
+ @Override
+ protected void configure() {
+ install(ConfigurationModule.create());
+ // Inject non-dependency configuration
+ requestInjection(BgpPolicyConfiguration.class);
+ }
+
+}
diff --git a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpRIBProvider.java b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpRIBProvider.java
index 76b34d5eb..8ced20b80 100644
--- a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpRIBProvider.java
+++ b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpRIBProvider.java
@@ -16,36 +16,38 @@
package io.fd.honeycomb.infra.bgp;
-import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.toTableTypes;
-
+import com.google.common.base.Preconditions;
import com.google.inject.Inject;
+import com.google.inject.name.Named;
import io.fd.honeycomb.binding.init.ProviderTrait;
import io.fd.honeycomb.data.init.ShutdownHandler;
import java.util.ArrayList;
-import java.util.Map;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.broker.impl.PingPongDataBroker;
-import org.opendaylight.controller.sal.core.api.model.SchemaService;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
-import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
-import org.opendaylight.protocol.bgp.mode.api.PathSelectionMode;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.BGPRibRoutingPolicyFactoryImpl;
+import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.StatementRegistry;
import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
+import org.opendaylight.protocol.bgp.rib.impl.CodecsRegistryImpl;
import org.opendaylight.protocol.bgp.rib.impl.RIBImpl;
-import org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionConsumerContext;
+import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRibRoutingPolicy;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.multiprotocol.rev151009.bgp.common.afi.safi.list.AfiSafi;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.RibId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.rib.TablesKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.BgpId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.ClusterIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.RibId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.BgpId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.ClusterIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -55,6 +57,8 @@ final class BgpRIBProvider extends ProviderTrait<RIB> {
@Inject
private BgpConfiguration cfg;
@Inject
+ private BgpPolicyConfiguration policyCfg;
+ @Inject
private RIBExtensionConsumerContext extensions;
@Inject
private BGPDispatcher dispatcher;
@@ -63,9 +67,12 @@ final class BgpRIBProvider extends ProviderTrait<RIB> {
@Inject
private DOMDataBroker domBroker;
@Inject
+ @Named(BgpModule.HONEYCOMB_BGP)
+ private DataBroker dataBroker;
+ @Inject
private BGPTableTypeRegistryConsumer tableTypeRegistry;
@Inject
- private SchemaService schemaService;
+ private DOMSchemaService schemaService;
@Inject
private ShutdownHandler shutdownHandler;
@Inject
@@ -73,6 +80,8 @@ final class BgpRIBProvider extends ProviderTrait<RIB> {
@Override
protected RIB create() {
+ Preconditions.checkArgument(policyCfg.getPolicyConfig().isPresent(),
+ "Bgp policy configuration failed to load. Check bgp-policy.json configuration file.");
final AsNumber asNumber = new AsNumber(cfg.bgpAsNumber.get().longValue());
final Ipv4Address routerId = new Ipv4Address(cfg.bgpBindingAddress.get());
final ClusterIdentifier clusterId = new ClusterIdentifier(routerId);
@@ -81,17 +90,18 @@ final class BgpRIBProvider extends ProviderTrait<RIB> {
// TODO(HONEYCOMB-363): configure other BGP Multiprotocol extensions:
final ArrayList<AfiSafi> afiSafiList = new ArrayList<>(configuredAfiSafis);
- final Map<TablesKey, PathSelectionMode> pathSelectionModes =
- OpenConfigMappingUtil.toPathSelectionMode(afiSafiList, tableTypeRegistry)
- .entrySet().stream().collect(Collectors.toMap(entry ->
- new TablesKey(entry.getKey().getAfi(), entry.getKey().getSafi()), Map.Entry::getValue));
// based on org.opendaylight.protocol.bgp.rib.impl.config.RibImpl.createRib
final PingPongDataBroker pingPongDataBroker = new PingPongDataBroker(domBroker);
- final RIBImpl rib =
- new RIBImpl(new RibId(cfg.bgpProtocolInstanceName.get()),
- asNumber, new BgpId(routerId), clusterId, extensions, dispatcher, codec,
- pingPongDataBroker, toTableTypes(afiSafiList, tableTypeRegistry), pathSelectionModes,
- extensions.getClassLoadingStrategy());
+ final CodecsRegistryImpl codecsRegistry =
+ CodecsRegistryImpl.create(codec, extensions.getClassLoadingStrategy());
+ final BGPRibRoutingPolicyFactoryImpl bgpRibRoutingPolicyFactory =
+ new BGPRibRoutingPolicyFactoryImpl(dataBroker, new StatementRegistry());
+ final BGPRibRoutingPolicy ribPolicies = bgpRibRoutingPolicyFactory
+ .buildBGPRibPolicy(cfg.bgpAsNumber.get(), new Ipv4Address(cfg.bgpBindingAddress.get()), clusterId,
+ policyCfg.getPolicyConfig().get());
+ final RIBImpl rib = new RIBImpl(tableTypeRegistry, new RibId(cfg.bgpProtocolInstanceName.get()),
+ asNumber, new BgpId(routerId), extensions, dispatcher, codecsRegistry, pingPongDataBroker, dataBroker,
+ ribPolicies, toTableTypes(afiSafiList, tableTypeRegistry), Collections.emptyMap());
rib.instantiateServiceInstance();
// required for proper RIB's CodecRegistry initialization (based on RIBImpl.start)
@@ -101,26 +111,13 @@ final class BgpRIBProvider extends ProviderTrait<RIB> {
return rib;
}
- /**
- * HC does not support clustering, but BGP uses {@link ClusterSingletonServiceProvider} to initialize {@link
- * RIBImpl}. Therefore we provide this dummy implementation.
- */
- private static final class NoopClusterSingletonServiceProvider implements ClusterSingletonServiceProvider {
- private static final Logger LOG = LoggerFactory.getLogger(NoopClusterSingletonServiceProvider.class);
-
- private static final ClusterSingletonServiceRegistration REGISTRATION =
- () -> LOG.debug("Closing ClusterSingletonServiceRegistration");
-
- @Override
- public ClusterSingletonServiceRegistration registerClusterSingletonService(
- final ClusterSingletonService clusterSingletonService) {
- clusterSingletonService.instantiateServiceInstance();
- return REGISTRATION;
- }
-
- @Override
- public void close() throws Exception {
- LOG.debug("Closing NoopClusterSingletonServiceProvider");
- }
+ private List<BgpTableType> toTableTypes(final List<AfiSafi> afiSafis,
+ final BGPTableTypeRegistryConsumer tableTypeRegistry) {
+ return afiSafis.stream()
+ .filter(afiSafi -> afiSafi.getAfiSafiName()!=null)
+ .map(afiSafi -> tableTypeRegistry.getTableType(afiSafi.getAfiSafiName()))
+ .filter(Optional::isPresent)
+ .map(Optional::get)
+ .collect(Collectors.toList());
}
}
diff --git a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpReaderFactoryProvider.java b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpReaderFactoryProvider.java
index 6f5bd5066..7ae724696 100644
--- a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpReaderFactoryProvider.java
+++ b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/BgpReaderFactoryProvider.java
@@ -24,8 +24,8 @@ import io.fd.honeycomb.translate.read.registry.ModifiableReaderRegistryBuilder;
import io.fd.honeycomb.translate.util.read.BindingBrokerReader;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.BgpRib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.BgpRibBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.BgpRib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.BgpRibBuilder;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
final class BgpReaderFactoryProvider extends ProviderTrait<ReaderFactory> {
diff --git a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/neighbors/BgpPeerWriterFactory.java b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/neighbors/BgpPeerWriterFactory.java
index 5e924be7e..e844cf3e0 100644
--- a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/neighbors/BgpPeerWriterFactory.java
+++ b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/neighbors/BgpPeerWriterFactory.java
@@ -22,6 +22,7 @@ import io.fd.honeycomb.translate.impl.write.GenericListWriter;
import io.fd.honeycomb.translate.write.WriterFactory;
import io.fd.honeycomb.translate.write.registry.ModifiableWriterRegistryBuilder;
import javax.annotation.Nonnull;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPPeerRegistry;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
@@ -32,8 +33,9 @@ import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.re
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstance;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.Protocols;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.Protocol1;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.NetworkInstanceProtocol;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.osgi.framework.BundleContext;
/**
* Initializes writer for Bgp Neighbors ({@link Neighbor} node) and all its parents required by HC infra.
@@ -47,7 +49,8 @@ public final class BgpPeerWriterFactory implements WriterFactory {
NETWORK_INSTANCE_ID.child(Protocols.class).child(Protocol.class);
private static final InstanceIdentifier<Neighbor> NEIGHBOR_ID =
- PROTOCOL_ID.augmentation(Protocol1.class).child(Bgp.class).child(Neighbors.class).child(Neighbor.class);
+ PROTOCOL_ID.augmentation(NetworkInstanceProtocol.class).child(Bgp.class).child(Neighbors.class)
+ .child(Neighbor.class);
@Inject
private BgpConfiguration configuration;
@@ -74,7 +77,8 @@ public final class BgpPeerWriterFactory implements WriterFactory {
// Bgp
// Neighbors
// Neighbor=
- registry.wildcardedSubtreeAdd(new GenericListWriter<>(NEIGHBOR_ID, new NeighborCustomizer(globalRib, peerRegistry, tableTypeRegistry)));
+ registry.wildcardedSubtreeAdd(new GenericListWriter<>(NEIGHBOR_ID, new NeighborCustomizer(globalRib, peerRegistry,
+ tableTypeRegistry, configuration)));
}
}
diff --git a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/neighbors/NeighborCustomizer.java b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/neighbors/NeighborCustomizer.java
index cdaffb6f6..ebe5795f1 100644
--- a/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/neighbors/NeighborCustomizer.java
+++ b/infra/northbound/bgp/src/main/java/io/fd/honeycomb/infra/bgp/neighbors/NeighborCustomizer.java
@@ -18,9 +18,9 @@ package io.fd.honeycomb.infra.bgp.neighbors;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
-import static org.opendaylight.protocol.bgp.rib.impl.config.OpenConfigMappingUtil.isApplicationPeer;
import com.google.common.annotations.VisibleForTesting;
+import io.fd.honeycomb.infra.bgp.BgpConfiguration;
import io.fd.honeycomb.translate.spi.write.ListWriterCustomizer;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
@@ -33,10 +33,19 @@ import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer
import org.opendaylight.protocol.bgp.rib.impl.config.AppPeer;
import org.opendaylight.protocol.bgp.rib.impl.config.BgpPeer;
import org.opendaylight.protocol.bgp.rib.impl.config.PeerBean;
+import org.opendaylight.protocol.bgp.rib.impl.config.PeerGroupConfigLoader;
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.bgp.neighbor.group.Config;
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.neighbors.NeighborKey;
+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.network.instance.rev151018.network.instance.top.NetworkInstances;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstance;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.Protocols;
+import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.protocols.Protocol;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.NeighborPeerGroupConfig;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev180329.NetworkInstanceProtocol;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,17 +59,24 @@ final class NeighborCustomizer implements ListWriterCustomizer<Neighbor, Neighbo
private static final Logger LOG = LoggerFactory.getLogger(NeighborCustomizer.class);
private final RIB globalRib;
private final BGPPeerRegistry peerRegistry;
+ private final PeerGroupConfigLoader peerGroupLoader;
private BGPTableTypeRegistryConsumer tableTypeRegistry;
+ @VisibleForTesting
+ static final InstanceIdentifier<Bgp> bgpIid = InstanceIdentifier.create(NetworkInstances.class)
+ .child(NetworkInstance.class).child(Protocols.class).child(Protocol.class).augmentation(
+ NetworkInstanceProtocol.class).child(Bgp.class);
@GuardedBy("this")
private final Map<InstanceIdentifier<Neighbor>, PeerBean> peers = new HashMap<>();
public NeighborCustomizer(@Nonnull final RIB globalRib, @Nonnull final BGPPeerRegistry peerRegistry,
- @Nonnull final BGPTableTypeRegistryConsumer tableTypeRegistry) {
+ @Nonnull final BGPTableTypeRegistryConsumer tableTypeRegistry,
+ final BgpConfiguration configuration) {
this.globalRib = checkNotNull(globalRib, "globalRib should not be null");
- this.peerRegistry = checkNotNull(peerRegistry, "globalRib should not be null");
+ this.peerRegistry = checkNotNull(peerRegistry, "peerRegistry should not be null");
this.tableTypeRegistry = checkNotNull(tableTypeRegistry, "tableTypeRegistry should not be null");
+ this.peerGroupLoader = checkNotNull(configuration, "configuration should not be null");
}
@VisibleForTesting
@@ -80,7 +96,7 @@ final class NeighborCustomizer implements ListWriterCustomizer<Neighbor, Neighbo
@Nonnull final WriteContext writeContext)
throws WriteFailedException {
final PeerBean peer;
- if (isApplicationPeer(neighbor)) {
+ if (isAppPeer(neighbor)) {
LOG.debug("Creating AppPeer bean for {}: {}", id, neighbor);
peer = new AppPeer();
} else {
@@ -88,11 +104,23 @@ final class NeighborCustomizer implements ListWriterCustomizer<Neighbor, Neighbo
peer = new BgpPeer(null);
}
LOG.debug("Starting bgp peer for {}", id);
- peer.start(globalRib, neighbor, tableTypeRegistry);
+ peer.start(globalRib, neighbor, bgpIid, peerGroupLoader, tableTypeRegistry);
peer.instantiateServiceInstance();
addPeer(id, peer);
}
+ static boolean isAppPeer(final Neighbor neighbor) {
+ Config config = neighbor.getConfig();
+ if (config != null) {
+ NeighborPeerGroupConfig config1 = config.augmentation(NeighborPeerGroupConfig.class);
+ if (config1 != null) {
+ String peerGroup = config1.getPeerGroup();
+ return peerGroup != null && peerGroup.equals("application-peers");
+ }
+ }
+ return false;
+ }
+
@Override
public synchronized void updateCurrentAttributes(@Nonnull final InstanceIdentifier<Neighbor> id,
@Nonnull final Neighbor dataBefore,
@@ -103,7 +131,7 @@ final class NeighborCustomizer implements ListWriterCustomizer<Neighbor, Neighbo
final PeerBean peer = peers.get(id);
checkState(peer != null, "Could not find peer bean while updating neighbor {}", id);
closePeerBean(peer);
- peer.start(globalRib, dataAfter, tableTypeRegistry);
+ peer.start(globalRib, dataAfter, bgpIid, peerGroupLoader, tableTypeRegistry);
peer.instantiateServiceInstance();
LOG.debug("Peer instance updated {}", peer);
}
diff --git a/infra/northbound/bgp/src/main/resources/honeycomb-minimal-resources/config/bgp-policy.json b/infra/northbound/bgp/src/main/resources/honeycomb-minimal-resources/config/bgp-policy.json
new file mode 100644
index 000000000..01abb6905
--- /dev/null
+++ b/infra/northbound/bgp/src/main/resources/honeycomb-minimal-resources/config/bgp-policy.json
@@ -0,0 +1,4 @@
+{
+ "default-import-policy": "ACCEPT-ROUTE",
+ "default-export-policy": "ACCEPT-ROUTE"
+} \ No newline at end of file