summaryrefslogtreecommitdiffstats
path: root/infra/northbound/bgp
diff options
context:
space:
mode:
authorMichal Cmarada <michal.cmarada@pantheon.tech>2018-09-25 11:15:35 +0200
committerMichal Cmarada <michal.cmarada@pantheon.tech>2018-09-25 11:22:18 +0200
commit556a0f59abc9b09005d40945bc20948d69e4f98e (patch)
tree76d795ae59aba49521fc4fdc7d65062c946147be /infra/northbound/bgp
parent46bcceb927b1bce07c1c9517f45470703293eb84 (diff)
Bump ODL dependencies to Fluorine (HONEYCOMB-433)
Change-Id: I142ebd2899272feff00abe7d4bae708f093ee3ec Signed-off-by: Michal Cmarada <michal.cmarada@pantheon.tech>
Diffstat (limited to 'infra/northbound/bgp')
-rw-r--r--infra/northbound/bgp/pom.xml5
-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
-rw-r--r--infra/northbound/bgp/src/test/java/io/fd/honeycomb/infra/bgp/neighbors/NeighborCustomizerTest.java67
12 files changed, 264 insertions, 78 deletions
diff --git a/infra/northbound/bgp/pom.xml b/infra/northbound/bgp/pom.xml
index f41e623fe..f8538f514 100644
--- a/infra/northbound/bgp/pom.xml
+++ b/infra/northbound/bgp/pom.xml
@@ -79,6 +79,11 @@
<groupId>org.opendaylight.bgpcep</groupId>
<artifactId>bgp-rib-impl</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>bgp-openconfig-rp-impl</artifactId>
+ <version>${odl.bgpcep.version}</version>
+ </dependency>
<!-- test dependencies -->
<dependency>
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
diff --git a/infra/northbound/bgp/src/test/java/io/fd/honeycomb/infra/bgp/neighbors/NeighborCustomizerTest.java b/infra/northbound/bgp/src/test/java/io/fd/honeycomb/infra/bgp/neighbors/NeighborCustomizerTest.java
index 64e0b9bd1..fadef81ab 100644
--- a/infra/northbound/bgp/src/test/java/io/fd/honeycomb/infra/bgp/neighbors/NeighborCustomizerTest.java
+++ b/infra/northbound/bgp/src/test/java/io/fd/honeycomb/infra/bgp/neighbors/NeighborCustomizerTest.java
@@ -25,12 +25,18 @@ import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FluentFuture;
+import com.google.common.util.concurrent.Futures;
+import io.fd.honeycomb.infra.bgp.BgpConfiguration;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
+import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
@@ -38,9 +44,10 @@ import org.opendaylight.protocol.bgp.openconfig.spi.BGPTableTypeRegistryConsumer
import org.opendaylight.protocol.bgp.rib.impl.config.PeerBean;
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.ImportPolicyPeerTracker;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIB;
import org.opendaylight.protocol.bgp.rib.impl.spi.RIBSupportContextRegistry;
+import org.opendaylight.protocol.bgp.rib.spi.BGPPeerTracker;
+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.AfiSafiBuilder;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.AfiSafisBuilder;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.ConfigBuilder;
@@ -50,14 +57,15 @@ import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.n
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.top.bgp.Neighbors;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.PeerType;
+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.IpAddress;
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.openconfig.extensions.rev171207.Config2;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev171207.Config2Builder;
-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.RibId;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.Rib;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.bgp.rib.RibKey;
+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.NeighborPeerGroupConfigBuilder;
+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.RibId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.Rib;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.bgp.rib.RibKey;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -78,41 +86,60 @@ public class NeighborCustomizerTest {
@Mock
private WriteContext ctx;
@Mock
- private DOMTransactionChain chain;
+ private BindingTransactionChain chain;
@Mock
- private DOMDataWriteTransaction tx;
+ private DOMTransactionChain domChain;
+ @Mock
+ private DOMDataWriteTransaction domTx;
+ @Mock
+ private WriteTransaction tx;
@Mock
private BGPDispatcher dispatcher;
private NeighborCustomizer customizer;
+ @Mock
+ private DataBroker dataBroker;
+ @Mock
+ private BgpConfiguration configuration;
@Before
public void setUp() {
initMocks(this);
when(globalRib.getYangRibId()).thenReturn(YangInstanceIdentifier.EMPTY);
when(globalRib.getInstanceIdentifier()).thenReturn(RIB_IID);
+ when(globalRib.getRibPolicies()).thenReturn(mock(BGPRibRoutingPolicy.class));
+
+ when(globalRib.createPeerDOMChain(any())).thenReturn(domChain);
+ when(domChain.newWriteOnlyTransaction()).thenReturn(domTx);
+ when(domTx.commit()).thenReturn(FluentFuture.from(Futures.immediateFuture(null)));
+
when(globalRib.createPeerChain(any())).thenReturn(chain);
when(chain.newWriteOnlyTransaction()).thenReturn(tx);
when(tx.submit()).thenReturn(mock(CheckedFuture.class));
- when(globalRib.getImportPolicyPeerTracker()).thenReturn(mock(ImportPolicyPeerTracker.class));
when(globalRib.getRibSupportContext()).thenReturn(mock(RIBSupportContextRegistry.class));
when(globalRib.getService()).thenReturn(mock(DOMDataTreeChangeService.class));
when(globalRib.getDispatcher()).thenReturn(dispatcher);
+ when(globalRib.getLocalAs()).thenReturn(new AsNumber(65000L));
+ when(globalRib.getDataBroker()).thenReturn(dataBroker);
+ when(globalRib.getPeerTracker()).thenReturn(mock(BGPPeerTracker.class));
when(dispatcher.getBGPPeerRegistry()).thenReturn(peerRegistry);
- customizer = new NeighborCustomizer(globalRib, peerRegistry, tableTypeRegistry);
+ when(dataBroker.newWriteOnlyTransaction()).thenReturn(tx);
+ when(tx.commit()).thenReturn(FluentFuture.from(Futures.immediateFuture(null)));
+
+ customizer = new NeighborCustomizer(globalRib, peerRegistry, tableTypeRegistry, configuration);
}
@Test
public void testAddAppPeer() throws WriteFailedException {
final Neighbor neighbor = new NeighborBuilder()
- .setNeighborAddress(IP)
- .setConfig(
- new ConfigBuilder()
- .addAugmentation(
- Config2.class,
- new Config2Builder().setPeerGroup("application-peers").build()
- ).build())
- .build();
+ .setNeighborAddress(IP)
+ .setConfig(
+ new ConfigBuilder()
+ .addAugmentation(
+ NeighborPeerGroupConfig.class,
+ new NeighborPeerGroupConfigBuilder().setPeerGroup("application-peers").build())
+ .build())
+ .build();
customizer.writeCurrentAttributes(ID, neighbor, ctx);
assertTrue(customizer.isPeerConfigured(ID));
}
@@ -143,7 +170,7 @@ public class NeighborCustomizerTest {
customizer.updateCurrentAttributes(ID, before, after, ctx);
verify(peer).closeServiceInstance();
verify(peer).close();
- verify(peer).start(globalRib, after, tableTypeRegistry);
+ verify(peer).start(globalRib, after, NeighborCustomizer.bgpIid, configuration, tableTypeRegistry);
}
@Test