--- /dev/null
+= bgp-distribution
+
+Honeycomb distribution that adds BGP to NETCONF and RESTCONF northbound intrerfaces provided by minimal-distribution.
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>io.fd.honeycomb.common</groupId>
+ <artifactId>minimal-distribution-parent</artifactId>
+ <version>1.17.07-SNAPSHOT</version>
+ <relativePath>../../common/minimal-distribution-parent</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>io.fd.honeycomb</groupId>
+ <artifactId>bgp-distribution</artifactId>
+ <name>${project.artifactId}</name>
+ <version>1.17.07-SNAPSHOT</version>
+
+ <properties>
+ <main.class>io.fd.honeycomb.infra.bgp.distro.Main</main.class>
+ <sonar.skip>true</sonar.skip>
+ <distribution.modules>
+ io.fd.honeycomb.infra.bgp.BgpModule,
+ io.fd.honeycomb.infra.bgp.BgpExtensionsModule,
+ io.fd.honeycomb.infra.bgp.BgpReadersModule,
+ io.fd.honeycomb.infra.bgp.BgpWritersModule,
+ io.fd.honeycomb.infra.bgp.BgpConfigurationModule
+ </distribution.modules>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.gmaven</groupId>
+ <artifactId>groovy-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>io.fd.honeycomb</groupId>
+ <artifactId>minimal-distribution</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- ODL-BGP -->
+ <dependency>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>bgp-rib-impl</artifactId>
+ <!-- TODO remove exclusion after bumping to Boron-SR4 -->
+ <exclusions>
+ <exclusion>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>bgp-openconfig-impl</artifactId>
+ </dependency>
+ <!-- BGP extensions -->
+ <dependency>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>bgp-evpn</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>bgp-inet</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>bgp-labeled-unicast</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>bgp-linkstate</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.bgpcep</groupId>
+ <artifactId>bgp-l3vpn</artifactId>
+ </dependency>
+
+ <!-- test dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.mashape.unirest</groupId>
+ <artifactId>unirest-java</artifactId>
+ <version>1.4.9</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.jcraft</groupId>
+ <artifactId>jsch</artifactId>
+ <version>0.1.54</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
* limitations under the License.
*/
-package io.fd.honeycomb.infra.distro.bgp;
+package io.fd.honeycomb.infra.bgp;
import com.google.inject.Inject;
import io.fd.honeycomb.infra.distro.ProviderTrait;
* limitations under the License.
*/
-package io.fd.honeycomb.infra.distro.bgp;
+package io.fd.honeycomb.infra.bgp;
import com.google.inject.Inject;
import io.fd.honeycomb.infra.distro.ProviderTrait;
import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContext;
import org.opendaylight.protocol.bgp.parser.spi.pojo.SimpleBGPExtensionProviderContextActivator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
final class BGPExtensionConsumerContextProvider extends ProviderTrait<BGPExtensionConsumerContext> {
+ private static final Logger LOG = LoggerFactory.getLogger(BGPExtensionConsumerContextProvider.class);
+
@Inject
private Set<BGPExtensionProviderActivator> activators;
final BGPExtensionProviderContext ctx = new SimpleBGPExtensionProviderContext();
final SimpleBGPExtensionProviderContextActivator activator =
new SimpleBGPExtensionProviderContextActivator(ctx, new ArrayList<>(activators));
+ LOG.debug("Starting BGPExtensionConsumerContext with activators: {}", activators);
activator.start();
return ctx;
}
* limitations under the License.
*/
-package io.fd.honeycomb.infra.distro.bgp;
+package io.fd.honeycomb.infra.bgp;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
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);
private static final String PEERS_CFG = "/bgp-peers.json";
@Inject
private BindingToNormalizedNodeCodec codec;
final Neighbors neighbors = readNeighbours();
for (final Neighbor neighbor : neighbors.getNeighbor()) {
if (isApplicationPeer(neighbor)) {
+ LOG.trace("Starting AppPeer for {}", neighbor);
new AppPeer().start(globalRib, neighbor, mappingService, null);
} else {
+ LOG.trace("Starting BgpPeer for {}", neighbor);
new BgpPeer(null, peerRegistry).start(globalRib, neighbor, mappingService, null);
}
}
+ LOG.debug("Created BGPPeerRegistry with neighbours {}", neighbors);
return peerRegistry;
}
private Neighbors readNeighbours() {
+ LOG.debug("Reading BGP neighbours from {}", PEERS_CFG);
final InputStream resourceStream = this.getClass().getResourceAsStream(PEERS_CFG);
checkState(resourceStream != null, "Resource %s not found", PEERS_CFG);
--- /dev/null
+/*
+ * Copyright (c) 2017 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.Optional;
+import net.jmob.guice.conf.core.BindConfig;
+import net.jmob.guice.conf.core.InjectConfig;
+import net.jmob.guice.conf.core.Syntax;
+
+/**
+ * This is the Java equivalent for bgp.json file. We use guice-config library to load all the config attributes
+ * into this class instance.
+ *
+ * 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 boolean isBgpEnabled() {
+ return Boolean.valueOf(bgpEnabled);
+ }
+
+ public boolean isBgpMultiplePathsEnabled() {
+ return Boolean.valueOf(bgpMultiplePaths.get());
+ }
+
+ @InjectConfig("bgp-enabled")
+ public String bgpEnabled;
+ @InjectConfig("bgp-binding-address")
+ public Optional<String> bgpBindingAddress;
+ @InjectConfig("bgp-port")
+ public Optional<Integer> bgpPort;
+ @InjectConfig("bgp-as-number")
+ public Optional<Integer> bgpAsNumber;
+ @InjectConfig("bgp-receive-multiple-paths")
+ public Optional<String> bgpMultiplePaths;
+ @InjectConfig("bgp-send-max-paths")
+ public Optional<Integer> bgpSendMaxMaths;
+ @InjectConfig("bgp-netty-threads")
+ public Integer bgpNettyThreads;
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(this)
+ .add("bgpEnabled", bgpEnabled)
+ .add("bgpBindingAddress", bgpBindingAddress)
+ .add("bgpPort", bgpPort)
+ .add("bgp-as-number", bgpAsNumber)
+ .add("bgp-netty-threads", bgpNettyThreads)
+ .add("bgp-receive-multiple-paths", bgpMultiplePaths)
+ .add("bgp-send-max-paths", bgpSendMaxMaths)
+ .toString();
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2017 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.
+ */
+public class BgpConfigurationModule extends AbstractModule {
+
+ protected void configure() {
+ install(ConfigurationModule.create());
+ // Inject non-dependency configuration
+ requestInjection(BgpConfiguration.class);
+ }
+
+}
* limitations under the License.
*/
-package io.fd.honeycomb.infra.distro.bgp;
+package io.fd.honeycomb.infra.bgp;
import com.google.inject.AbstractModule;
import com.google.inject.multibindings.Multibinder;
* limitations under the License.
*/
-package io.fd.honeycomb.infra.distro.bgp;
+package io.fd.honeycomb.infra.bgp;
import static io.fd.honeycomb.infra.distro.data.InmemoryDOMDataBrokerProvider.CONFIG;
import static io.fd.honeycomb.infra.distro.data.InmemoryDOMDataBrokerProvider.OPERATIONAL;
* limitations under the License.
*/
-package io.fd.honeycomb.infra.distro.bgp;
+package io.fd.honeycomb.infra.bgp;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.inject.Inject;
import io.fd.honeycomb.infra.distro.ProviderTrait;
-import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration;
import io.netty.channel.nio.NioEventLoopGroup;
final class BgpNettyThreadGroupProvider extends ProviderTrait<NioEventLoopGroup> {
@Inject
- private HoneycombConfiguration cfgAttributes;
+ private BgpConfiguration cfgAttributes;
@Override
protected NioEventLoopGroup create() {
* limitations under the License.
*/
-package io.fd.honeycomb.infra.distro.bgp;
+package io.fd.honeycomb.infra.bgp;
import com.google.common.collect.ImmutableList;
import com.google.inject.Inject;
import io.fd.honeycomb.infra.distro.ProviderTrait;
-import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.slf4j.LoggerFactory;
final class BgpRIBProvider extends ProviderTrait<RIB> {
-
+ private static final Logger LOG = LoggerFactory.getLogger(BgpRIBProvider.class);
private static final String HC_BGP_INSTANCE_NAME = "hc-bgp-instance";
@Inject
- private HoneycombConfiguration cfg;
+ private BgpConfiguration cfg;
@Inject
private RIBExtensionConsumerContext extensions;
@Inject
final AsNumber asNumber = new AsNumber(cfg.bgpAsNumber.get().longValue());
final Ipv4Address routerId = new Ipv4Address(cfg.bgpBindingAddress.get());
final ClusterIdentifier clusterId = new ClusterIdentifier(routerId);
+ LOG.debug("Creating BGP RIB: routerId={}, asNumber={}", routerId, asNumber);
// TODO configure other BGP Multiprotocol extensions:
final List<AfiSafi> afiSafi = ImmutableList.of(new AfiSafiBuilder().setAfiSafiName(IPV4UNICAST.class)
.addAugmentation(AfiSafi2.class,
// required for proper RIB's CodecRegistry initialization (based on RIBImpl.start)
schemaService.registerSchemaContextListener(rib);
+
+ LOG.debug("BGP RIB created successfully: {}", rib);
return rib;
}
* limitations under the License.
*/
-package io.fd.honeycomb.infra.distro.bgp;
+package io.fd.honeycomb.infra.bgp;
import com.google.inject.Inject;
import com.google.inject.name.Named;
* limitations under the License.
*/
-package io.fd.honeycomb.infra.distro.bgp;
+package io.fd.honeycomb.infra.bgp;
import com.google.inject.AbstractModule;
import com.google.inject.Singleton;
* limitations under the License.
*/
-package io.fd.honeycomb.infra.distro.bgp;
+package io.fd.honeycomb.infra.bgp;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import io.fd.honeycomb.infra.distro.ProviderTrait;
-import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration;
import io.netty.channel.Channel;
import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelFuture;
import org.opendaylight.protocol.concepts.KeyMapping;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IetfInetUtil;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public final class BgpServerProvider extends ProviderTrait<BgpServerProvider.BgpServer> {
+ private static final Logger LOG = LoggerFactory.getLogger(BgpServerProvider.class);
@Inject
- private HoneycombConfiguration cfg;
+ private BgpConfiguration cfg;
@Inject
private BGPPeerRegistry peerRegistry;
@Inject
throw new IllegalArgumentException("Illegal BGP binding address", e);
}
final InetSocketAddress address = new InetSocketAddress(bindingAddress, cfg.bgpPort.get());
+ LOG.debug("Creating BgpServer for {}", address);
final ChannelFuture localServer = dispatcher.createServer(peerRegistry, address);
localServer.addListener(future -> {
Preconditions.checkArgument(future.isSuccess(), "Unable to start bgp server on %s", address, future.cause());
peerRegistry.registerPeerRegisterListener(new PeerRegistryListenerImpl(channel.config()));
}
});
- return new BgpServer(localServer);
+ final BgpServer server = new BgpServer(localServer);
+ LOG.debug("BgpServer successfully created.");
+ return server;
}
public static final class BgpServer {
* limitations under the License.
*/
-package io.fd.honeycomb.infra.distro.bgp;
+package io.fd.honeycomb.infra.bgp;
import com.google.common.collect.Sets;
import com.google.inject.Inject;
this.dataBroker = dataBroker;
}
- // TODO
+ // TODO (HONEYCOMB-359):
// BGP models are huge, we need some kind of wildcarded subtree writer, that works for whole subtree.
// 1) we can either move checking handledTypes to writers (getHandledTypes, isAffected, writer.getHandedTypes, ...)
// but then precondition check in flatWriterRegistry might be slower (we need to check if we have all writers
* limitations under the License.
*/
-package io.fd.honeycomb.infra.distro.bgp;
+package io.fd.honeycomb.infra.bgp;
import com.google.inject.AbstractModule;
import com.google.inject.Singleton;
* limitations under the License.
*/
-package io.fd.honeycomb.infra.distro.bgp;
+package io.fd.honeycomb.infra.bgp;
import com.google.inject.Inject;
import io.fd.honeycomb.infra.distro.ProviderTrait;
import org.opendaylight.protocol.bgp.rib.spi.RIBExtensionProviderContext;
import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContext;
import org.opendaylight.protocol.bgp.rib.spi.SimpleRIBExtensionProviderContextActivator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class RIBExtensionConsumerContextProvider extends ProviderTrait<RIBExtensionConsumerContext> {
+ private static final Logger LOG = LoggerFactory.getLogger(RIBExtensionConsumerContextProvider.class);
@Inject
private Set<RIBExtensionProviderActivator> activators;
final RIBExtensionProviderContext ctx = new SimpleRIBExtensionProviderContext();
final SimpleRIBExtensionProviderContextActivator activator =
new SimpleRIBExtensionProviderContextActivator(ctx, new ArrayList<>(activators));
+ LOG.debug("Starting RIBExtensionConsumerContext with activators: {}", activators);
activator.start();
return ctx;
}
--- /dev/null
+/*
+ * Copyright (c) 2017 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.distro;
+
+import static io.fd.honeycomb.infra.distro.ActiveModuleProvider.STANDARD_MODULES_RELATIVE_PATH;
+import static io.fd.honeycomb.infra.distro.ActiveModuleProvider.aggregateResources;
+import static io.fd.honeycomb.infra.distro.ActiveModuleProvider.loadActiveModules;
+
+import com.google.inject.ConfigurationException;
+import com.google.inject.CreationException;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class Main {
+
+ private static final Logger LOG = LoggerFactory.getLogger(Main.class);
+
+ private Main() {
+ }
+
+ public static void main(String[] args) {
+ final ClassLoader classLoader = Main.class.getClassLoader();
+ init(loadActiveModules(aggregateResources(STANDARD_MODULES_RELATIVE_PATH, classLoader)));
+ }
+
+ /**
+ * Initialize the Honeycomb with provided modules
+ */
+ public static Injector init(final Set<? extends Module> modules) {
+ try {
+ Injector injector = io.fd.honeycomb.infra.distro.Main.init(modules);
+ final BgpConfiguration bgpAttributes = injector.getInstance(BgpConfiguration.class);
+
+ if (bgpAttributes.isBgpEnabled()) {
+ LOG.info("Starting BGP");
+ injector.getInstance(BgpServerProvider.BgpServer.class);
+ LOG.info("BGP started successfully!");
+ }
+
+ return injector;
+ } catch (CreationException | ProvisionException | ConfigurationException e) {
+ LOG.error("Failed to initialize Honeycomb components", e);
+ throw e;
+ } catch (RuntimeException e) {
+ LOG.error("Unexpected initialization failure", e);
+ throw e;
+ } finally {
+ // Trigger gc to force collect initial garbage + dedicated classloader
+ System.gc();
+ }
+ }
+
+}
--- /dev/null
+{
+ "bgp-enabled": "true",
+ "bgp-binding-address": "127.0.0.1",
+ "bgp-port": 1790,
+ "bgp-as-number": 65000,
+ "bgp-receive-multiple-paths": "true",
+ "bgp-send-max-paths": 0,
+ "bgp-netty-threads": 2
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 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.distro;
+
+import static com.google.common.collect.ImmutableSet.of;
+
+import com.google.common.io.ByteStreams;
+import com.google.inject.Module;
+import com.mashape.unirest.http.Unirest;
+import io.fd.honeycomb.infra.bgp.BgpConfigurationModule;
+import io.fd.honeycomb.infra.bgp.BgpExtensionsModule;
+import io.fd.honeycomb.infra.bgp.BgpModule;
+import io.fd.honeycomb.infra.bgp.BgpReadersModule;
+import io.fd.honeycomb.infra.bgp.BgpWritersModule;
+import io.fd.honeycomb.infra.distro.cfgattrs.CfgAttrsModule;
+import io.fd.honeycomb.infra.distro.data.ConfigAndOperationalPipelineModule;
+import io.fd.honeycomb.infra.distro.data.context.ContextPipelineModule;
+import io.fd.honeycomb.infra.distro.initializer.InitializerPipelineModule;
+import io.fd.honeycomb.infra.distro.netconf.NetconfModule;
+import io.fd.honeycomb.infra.distro.netconf.NetconfReadersModule;
+import io.fd.honeycomb.infra.distro.restconf.RestconfModule;
+import io.fd.honeycomb.infra.distro.schema.SchemaModule;
+import io.fd.honeycomb.infra.distro.schema.YangBindingProviderModule;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.util.Set;
+import javax.net.ssl.SSLContext;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.ssl.SSLContexts;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BgpDistributionTest {
+
+ private static final Logger LOG = LoggerFactory.getLogger(BgpDistributionTest.class);
+ private static final String CERT_PASSWORD = "testing";
+ private static final int HELLO_WAIT = 2500;
+
+ private static final int BGP_MSG_TYPE_OFFSET = 18; // 16 (MARKER) + 2 (LENGTH);
+ private static final byte BGP_OPEN_MSG_TYPE = 1;
+ private static final int BGP_PORT = 1790;
+
+ public static final Set<Module> BASE_MODULES = of(
+ new YangBindingProviderModule(),
+ new SchemaModule(),
+ new ConfigAndOperationalPipelineModule(),
+ new ContextPipelineModule(),
+ new InitializerPipelineModule(),
+ new NetconfModule(),
+ new NetconfReadersModule(),
+ new RestconfModule(),
+ new CfgAttrsModule(),
+ new BgpModule(),
+ new BgpExtensionsModule(),
+ new BgpReadersModule(),
+ new BgpWritersModule(),
+ new BgpConfigurationModule());
+
+ @Before
+ public void setUp() throws Exception {
+ SSLContext sslcontext = SSLContexts.custom()
+ .loadTrustMaterial(getClass().getResource("/honeycomb-keystore"),
+ CERT_PASSWORD.toCharArray(), new TrustSelfSignedStrategy())
+ .build();
+
+ SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext);
+ CloseableHttpClient httpclient = HttpClients.custom()
+ .setSSLSocketFactory(sslsf)
+ .build();
+ Unirest.setHttpClient(httpclient);
+ }
+
+ @Test(timeout = 60000)
+ public void test() throws Exception {
+ io.fd.honeycomb.infra.bgp.distro.Main.init(BASE_MODULES);
+ LOG.info("Testing Honeycomb BGP distribution");
+ assertBgp();
+ }
+
+ private byte[] readMessage(final InputStream inputStream) throws IOException {
+ final int available = inputStream.available();
+ final byte[] msg = new byte[available];
+ ByteStreams.read(inputStream, msg, 0, available);
+ return msg;
+ }
+
+ private void assertBgp() throws Exception {
+ // Wait until BGP server is started
+ Thread.sleep(HELLO_WAIT);
+ final InetAddress bgpHost = InetAddress.getByName("127.0.0.1");
+ final InetAddress bgpPeerAddress = InetAddress.getByName("127.0.0.2");
+ try (final Socket localhost = new Socket(bgpHost, BGP_PORT, bgpPeerAddress, 0);
+ final InputStream inputStream = localhost.getInputStream()) {
+ // Wait until bgp message is sent
+ Thread.sleep(HELLO_WAIT);
+
+ final byte[] msg = readMessage(inputStream);
+ LOG.info("Received BGP message: {}", msg);
+
+ Assert.assertEquals(BGP_OPEN_MSG_TYPE, msg[BGP_MSG_TYPE_OFFSET]);
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ ~ Copyright (c) 2016 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.
+ -->
+
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ version="3.0">
+
+ <servlet>
+ <servlet-name>JAXRSRestconf</servlet-name>
+ <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.opendaylight.netconf.sal.rest.impl.RestconfApplication</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>JAXRSRestconf</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+ <filter>
+ <filter-name>cross-origin-restconf</filter-name>
+ <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
+ <init-param>
+ <param-name>allowedOrigins</param-name>
+ <param-value>*</param-value>
+ </init-param>
+ <init-param>
+ <param-name>allowedMethods</param-name>
+ <param-value>GET,POST,OPTIONS,DELETE,PUT,HEAD</param-value>
+ </init-param>
+ <init-param>
+ <param-name>allowedHeaders</param-name>
+ <param-value>origin, content-type, accept, authorization</param-value>
+ </init-param>
+ <init-param>
+ <param-name>exposedHeaders</param-name>
+ <param-value>location</param-value>
+ </init-param>
+ </filter>
+ <filter-mapping>
+ <filter-name>cross-origin-restconf</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>NB api</web-resource-name>
+ <url-pattern>/*</url-pattern>
+ <http-method>POST</http-method>
+ <http-method>GET</http-method>
+ <http-method>PUT</http-method>
+ <http-method>PATCH</http-method>
+ <http-method>DELETE</http-method>
+ <http-method>HEAD</http-method>
+ </web-resource-collection>
+ </security-constraint>
+
+</web-app>
--- /dev/null
+ {
+ "bgp-enabled": "true",
+ "bgp-binding-address": "127.0.0.1",
+ "bgp-port": 1790,
+ "bgp-as-number": 65000,
+ "bgp-receive-multiple-paths": "true",
+ "bgp-send-max-paths": 0,
+ "bgp-netty-threads": 2
+}
\ No newline at end of file
--- /dev/null
+ {
+ "persisted-context-path": "/tmp/honeycomb/persist/context/data.json",
+ "persisted-context-restoration-type": "Merge",
+ "persisted-config-path": "/tmp/honeycomb/persist/config/data.json",
+ "persisted-config-restoration-type": "Merge",
+
+ "notification-service-queue-depth": 1,
+
+ "restconf-http-enabled": "true",
+ "restconf-root-path": "/restconf",
+ "restconf-binding-address": "127.0.0.1",
+ "restconf-port": 8182,
+ "restconf-https-enabled": "true",
+ "restconf-https-binding-address": "127.0.0.1",
+ "restconf-https-port": 8444,
+ "restconf-keystore": "/honeycomb-keystore",
+ "restconf-keystore-password": "testing",
+ "restconf-keystore-manager-password": "testing",
+ "restconf-truststore": "/honeycomb-keystore",
+ "restconf-truststore-password": "testing",
+ "restconf-websocket-port": 7780,
+ "restconf-pool-max-size": 10,
+ "restconf-pool-min-size": 1,
+ "restconf-acceptors-size": 1,
+ "restconf-selectors-size": 1,
+ "restconf-https-acceptors-size": 1,
+ "restconf-https-selectors-size": 1,
+
+ "netconf-netty-threads": 2,
+ "netconf-tcp-enabled" : "true",
+ "netconf-tcp-binding-address": "127.0.0.1",
+ "netconf-tcp-binding-port": 7778,
+ "netconf-ssh-enabled" : "true",
+ "netconf-ssh-binding-address": "127.0.0.1",
+ "netconf-ssh-binding-port": 2832,
+ "netconf-notification-stream-name": "honeycomb",
+
+ "username": "admin",
+ "password": "admin"
+}
\ No newline at end of file
--- /dev/null
+ <!--
+ ~ Copyright (c) 2016 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.
+ -->
+
+<configuration scan="true">
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>%date{"yyyy-MM-dd HH:mm:ss.SSS z"} [%thread] %-5level %logger{36} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <root level="warn">
+ <appender-ref ref="STDOUT" />
+ </root>
+
+ <logger name="org.opendaylight" level="INFO"/>
+ <logger name="io.fd" level="INFO"/>
+</configuration>
io.fd.honeycomb.infra.distro.netconf.NetconfModule,
io.fd.honeycomb.infra.distro.netconf.NetconfReadersModule,
io.fd.honeycomb.infra.distro.restconf.RestconfModule,
- io.fd.honeycomb.infra.distro.bgp.BgpModule,
- io.fd.honeycomb.infra.distro.bgp.BgpExtensionsModule,
- io.fd.honeycomb.infra.distro.bgp.BgpReadersModule,
- io.fd.honeycomb.infra.distro.bgp.BgpWritersModule,
io.fd.honeycomb.infra.distro.cfgattrs.CfgAttrsModule
</distribution.modules>
</properties>
<groupId>org.opendaylight.netconf</groupId>
<artifactId>ietf-netconf-monitoring-extension</artifactId>
</dependency>
- <!-- ODL-BGP -->
- <dependency>
- <groupId>org.opendaylight.bgpcep</groupId>
- <artifactId>bgp-rib-impl</artifactId>
- <!-- TODO remove exclusion after bumping to Boron-SR4 -->
- <exclusions>
- <exclusion>
- <groupId>org.powermock</groupId>
- <artifactId>powermock</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.bgpcep</groupId>
- <artifactId>bgp-openconfig-impl</artifactId>
- </dependency>
- <!-- BGP extensions -->
- <dependency>
- <groupId>org.opendaylight.bgpcep</groupId>
- <artifactId>bgp-evpn</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.bgpcep</groupId>
- <artifactId>bgp-inet</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.bgpcep</groupId>
- <artifactId>bgp-labeled-unicast</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.bgpcep</groupId>
- <artifactId>bgp-linkstate</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.bgpcep</groupId>
- <artifactId>bgp-l3vpn</artifactId>
- </dependency>
-
<!-- Jersey + Jetty for RESTCONF -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
import com.google.inject.name.Names;
import io.fd.honeycomb.data.init.DataTreeInitializer;
import io.fd.honeycomb.data.init.InitializerRegistry;
-import io.fd.honeycomb.infra.distro.bgp.BgpServerProvider;
import io.fd.honeycomb.infra.distro.cfgattrs.HoneycombConfiguration;
import io.fd.honeycomb.infra.distro.initializer.InitializerPipelineModule;
import io.fd.honeycomb.infra.distro.netconf.HoneycombNotification2NetconfProvider;
injector.getInstance(HoneycombNotification2NetconfProvider.HoneycombNotification2Netconf.class);
}
- if (cfgAttributes.isBgpEnabled()) {
- LOG.info("Starting BGP");
- injector.getInstance(BgpServerProvider.BgpServer.class);
- }
-
try {
LOG.info("Initializing configuration");
injector.getInstance(Key.get(InitializerRegistry.class,
return isNetconfTcpEnabled() || isNetconfSshEnabled();
}
- public boolean isBgpEnabled() {
- return Boolean.valueOf(bgpEnabled);
- }
-
public boolean isConfigPersistenceEnabled() {
return persistConfig.isPresent() && Boolean.valueOf(persistConfig.get());
}
return persistContext.isPresent() && Boolean.valueOf(persistContext.get());
}
- public boolean isBgpMultiplePathsEnabled() {
- return Boolean.valueOf(bgpMultiplePaths.get());
- }
-
@InjectConfig("persist-context")
public Optional<String> persistContext = Optional.of("true");
@InjectConfig("persisted-context-path")
public Optional<Integer> netconfSshBindingPort;
@InjectConfig("netconf-notification-stream-name")
public Optional<String> netconfNotificationStreamName = Optional.of("honeycomb");
- @InjectConfig("bgp-enabled")
- public String bgpEnabled;
- @InjectConfig("bgp-binding-address")
- public Optional<String> bgpBindingAddress;
- @InjectConfig("bgp-port")
- public Optional<Integer> bgpPort;
- @InjectConfig("bgp-as-number")
- public Optional<Integer> bgpAsNumber;
- @InjectConfig("bgp-receive-multiple-paths")
- public Optional<String> bgpMultiplePaths;
- @InjectConfig("bgp-send-max-paths")
- public Optional<Integer> bgpSendMaxMaths;
- @InjectConfig("bgp-netty-threads")
- public Integer bgpNettyThreads;
@InjectConfig("username")
public String username;
@InjectConfig("password")
.add("netconfSshBindingAddress", netconfSshBindingAddress)
.add("netconfSshBindingPort", netconfSshBindingPort)
.add("netconfNotificationStreamName", netconfNotificationStreamName)
- .add("bgpEnabled", bgpEnabled)
- .add("bgpBindingAddress", bgpBindingAddress)
- .add("bgpPort", bgpPort)
- .add("bgp-as-number", bgpAsNumber)
- .add("bgp-netty-threads", bgpNettyThreads)
- .add("bgp-receive-multiple-paths", bgpMultiplePaths)
- .add("bgp-send-max-paths", bgpSendMaxMaths)
.add("username", username)
.add("password", password)
.toString();
{
- "persist-context": "false",
+ "persist-context": "true",
"persisted-context-path": "/var/lib/honeycomb/persist/context/data.json",
"persisted-context-restoration-type": "Merge",
- "persist-config": "false",
+ "persist-config": "true",
"persisted-config-path": "/var/lib/honeycomb/persist/config/data.json",
"persisted-config-restoration-type": "Merge",
"netconf-ssh-binding-port": 2831,
"netconf-notification-stream-name": "honeycomb",
- "bgp-enabled": "true",
- "bgp-binding-address": "127.0.0.1",
- "bgp-port": 1790,
- "bgp-as-number": 65000,
- "bgp-receive-multiple-paths": "true",
- "bgp-send-max-paths": 0,
- "bgp-netty-threads": 2,
-
"username": "admin",
"password": "admin"
}
\ No newline at end of file
</encoder>
</appender>
<appender name="honeycomb.log" class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>honeycomb.log</file>
+ <file>/var/log/honeycomb/honeycomb.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
- <fileNamePattern>logs/honeycomb.%d.log.zip</fileNamePattern>
+ <fileNamePattern>/var/log/honeycomb/logs/honeycomb.%d.log.zip</fileNamePattern>
<maxHistory>1</maxHistory>
</rollingPolicy>
import static com.google.common.collect.ImmutableSet.of;
import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import com.jcraft.jsch.Session;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
-import io.fd.honeycomb.infra.distro.bgp.BgpExtensionsModule;
-import io.fd.honeycomb.infra.distro.bgp.BgpModule;
-import io.fd.honeycomb.infra.distro.bgp.BgpReadersModule;
-import io.fd.honeycomb.infra.distro.bgp.BgpWritersModule;
import io.fd.honeycomb.infra.distro.cfgattrs.CfgAttrsModule;
import io.fd.honeycomb.infra.distro.data.ConfigAndOperationalPipelineModule;
import io.fd.honeycomb.infra.distro.data.context.ContextPipelineModule;
import io.fd.honeycomb.infra.distro.schema.YangBindingProviderModule;
import java.io.IOException;
import java.io.InputStream;
-import java.net.InetAddress;
import java.net.Socket;
import java.util.Properties;
import java.util.Set;
private static final String NETCONF_NAMESPACE = "urn:ietf:params:xml:ns:netconf:base:1.0";
private static final int HELLO_WAIT = 2500;
- private static final int BGP_MSG_TYPE_OFFSET = 18; // 16 (MARKER) + 2 (LENGTH);
- private static final byte BGP_OPEN_MSG_TYPE = 1;
- private static final int BGP_PORT = 1790;
-
public static final Set<Module> BASE_MODULES = of(
- new YangBindingProviderModule(),
- new SchemaModule(),
- new ConfigAndOperationalPipelineModule(),
- new ContextPipelineModule(),
- new InitializerPipelineModule(),
- new NetconfModule(),
- new NetconfReadersModule(),
- new RestconfModule(),
- new BgpModule(),
- new BgpExtensionsModule(),
- new BgpReadersModule(),
- new BgpWritersModule(),
- new CfgAttrsModule());
+ new YangBindingProviderModule(),
+ new SchemaModule(),
+ new ConfigAndOperationalPipelineModule(),
+ new ContextPipelineModule(),
+ new InitializerPipelineModule(),
+ new NetconfModule(),
+ new NetconfReadersModule(),
+ new RestconfModule(),
+ new CfgAttrsModule());
@Before
public void setUp() throws Exception {
SSLContext sslcontext = SSLContexts.custom()
- .loadTrustMaterial(getClass().getResource("/honeycomb-keystore"),
- CERT_PASSWORD.toCharArray(), new TrustSelfSignedStrategy())
- .build();
+ .loadTrustMaterial(getClass().getResource("/honeycomb-keystore"),
+ CERT_PASSWORD.toCharArray(), new TrustSelfSignedStrategy())
+ .build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext);
CloseableHttpClient httpclient = HttpClients.custom()
- .setSSLSocketFactory(sslsf)
- .build();
+ .setSSLSocketFactory(sslsf)
+ .build();
Unirest.setHttpClient(httpclient);
}
assertRestconfHttp();
LOG.info("Testing RESTCONF HTTPS");
assertRestconfHttps();
- LOG.info("Testing BGP");
- assertBgp();
}
private void assertNetconfTcp() throws Exception {
private void assertRestconfHttp() throws Exception {
final String url =
- "http://127.0.0.1:" + HTTP_PORT + "/restconf/operational/ietf-netconf-monitoring:netconf-state";
+ "http://127.0.0.1:" + HTTP_PORT + "/restconf/operational/ietf-netconf-monitoring:netconf-state";
LOG.info("RESTCONF HTTP GET to {}", url);
final HttpResponse<String> jsonNodeHttpResponse = Unirest.get(url)
- .basicAuth(UNAME, PASSWORD)
- .asString();
+ .basicAuth(UNAME, PASSWORD)
+ .asString();
LOG.info("RESTCONF HTTP GET to {}, status: {}, data: {}",
- url, jsonNodeHttpResponse.getStatus(), jsonNodeHttpResponse.getBody());
+ url, jsonNodeHttpResponse.getStatus(), jsonNodeHttpResponse.getBody());
assertSuccessStatus(jsonNodeHttpResponse);
assertSuccessResponseForNetconfMonitoring(jsonNodeHttpResponse);
private void assertRestconfHttps() throws Exception {
final String url =
- "https://127.0.0.1:" + HTTPS_PORT + "/restconf/operational/ietf-netconf-monitoring:netconf-state";
+ "https://127.0.0.1:" + HTTPS_PORT + "/restconf/operational/ietf-netconf-monitoring:netconf-state";
LOG.info("RESTCONF HTTPS GET to {}", url);
final HttpResponse<String> jsonNodeHttpResponse = Unirest.get(url)
- .basicAuth(UNAME, PASSWORD)
- .asString();
+ .basicAuth(UNAME, PASSWORD)
+ .asString();
LOG.info("RESTCONF HTTPS GET to {}, status: {}, data: {}",
- url, jsonNodeHttpResponse.getStatus(), jsonNodeHttpResponse.getBody());
+ url, jsonNodeHttpResponse.getStatus(), jsonNodeHttpResponse.getBody());
assertSuccessStatus(jsonNodeHttpResponse);
assertSuccessResponseForNetconfMonitoring(jsonNodeHttpResponse);
assertTrue(jsonNodeHttpResponse.getStatus() >= 200);
assertTrue(jsonNodeHttpResponse.getStatus() < 400);
}
-
- private void assertBgp() throws Exception {
- final InetAddress bgpHost = InetAddress.getByName("127.0.0.1");
- final InetAddress bgpPeerAddress = InetAddress.getByName("127.0.0.2");
- try (final Socket localhost = new Socket(bgpHost, BGP_PORT, bgpPeerAddress, 0);
- final InputStream inputStream = localhost.getInputStream()) {
- // wait until bgp message is sent
- Thread.sleep(HELLO_WAIT);
-
- final byte[] msg = readMessage(inputStream);
- LOG.info("Received BGP message: {}", msg);
-
- assertEquals(BGP_OPEN_MSG_TYPE, msg[BGP_MSG_TYPE_OFFSET]);
- }
- }
}
\ No newline at end of file
"netconf-ssh-binding-port": 2832,
"netconf-notification-stream-name": "honeycomb",
- "bgp-enabled": "true",
- "bgp-binding-address": "127.0.0.1",
- "bgp-port": 1790,
- "bgp-as-number": 65000,
- "bgp-receive-multiple-paths": "true",
- "bgp-send-max-paths": 0,
- "bgp-netty-threads": 2,
-
"username": "admin",
"password": "admin"
}
\ No newline at end of file
<module>cfg-init</module>
<module>impl</module>
<module>minimal-distribution</module>
+ <module>bgp-distribution</module>
<module>it</module>
<module>test-utils</module>
<module>rpc</module>
/**
* Simple DataBroker backed writer allowing to delegate writes to different brokers.
*/
-public final class BindingBrokerWriter<D extends DataObject>
- implements Writer<D> {
-
+public final class BindingBrokerWriter<D extends DataObject> implements Writer<D> {
private final InstanceIdentifier<D> instanceIdentifier;
private final DataBroker dataBroker;