From 46589c652a58b1cd56dab268b59d96bc20b5dd1f Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Fri, 31 Mar 2017 11:24:24 +0200 Subject: Include ODL's BGP to HC minimal distro Features: - static bgp instance - static peer registry (both remote & app peers supported) - bgp operational state exposed via RESTCONF/NETCONF - bgp-inet support - postman collection with examples TODOs: - make bgp disabled by default in honeycomb.json (probably bgp should be build using profile or allow to filter yangs loaded by SchemaCtx, otherwise footprint will grow) - update asciidocs for infra module - SPI for VPP integration: - allow RIB changes listeners - or writers (that can reject changes) to mirror netconf/restconf design - expose bgp server & peer cfg via netconf/restconf (currently read from json files) - test support for all BGP extensions (flowspec BGP needs additional care) - make bgp extensions fully configurable (probably requires changes in ODL) Testing 1) start hc distro: ./infra/minimal-distribution/target/minimal-distribution-1.17.07-SNAPSHOT-hc/minimal-distribution-1.17.07-SNAPSHOT/honeycomb 2) run bgp-testtool: java -jar ./target/bgp-testtool-0.6.3-Boron-SR3-executable.jar -ra 127.0.0.1:1790 -la 127.0.0.2:17900 -pr 2 -ll DEBUG --active true -as 65000 -mp true then GET http://localhost:8183/restconf/operational/bgp-rib:bgp-rib Change-Id: I156d6a1c79174279db8c8936c40ac1f28e14794c Signed-off-by: Marek Gradzki --- .../infra/distro/BaseMinimalDistributionTest.java | 49 ++++++++++++++++++---- 1 file changed, 41 insertions(+), 8 deletions(-) (limited to 'infra/minimal-distribution/src/test/java/io/fd/honeycomb/infra/distro/BaseMinimalDistributionTest.java') diff --git a/infra/minimal-distribution/src/test/java/io/fd/honeycomb/infra/distro/BaseMinimalDistributionTest.java b/infra/minimal-distribution/src/test/java/io/fd/honeycomb/infra/distro/BaseMinimalDistributionTest.java index 8a8ddc3ef..fdd265b79 100644 --- a/infra/minimal-distribution/src/test/java/io/fd/honeycomb/infra/distro/BaseMinimalDistributionTest.java +++ b/infra/minimal-distribution/src/test/java/io/fd/honeycomb/infra/distro/BaseMinimalDistributionTest.java @@ -18,6 +18,7 @@ package io.fd.honeycomb.infra.distro; 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; @@ -30,6 +31,10 @@ import com.jcraft.jsch.JSch; 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; @@ -41,8 +46,8 @@ 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.List; import java.util.Properties; import java.util.Set; import javax.net.ssl.SSLContext; @@ -68,7 +73,11 @@ public class BaseMinimalDistributionTest { private static final int NETCONF_TCP_PORT = 7778; private static final int NETCONF_SSH_PORT = 2832; private static final String NETCONF_NAMESPACE = "urn:ietf:params:xml:ns:netconf:base:1.0"; - private static final int NETCONF_HELLO_WAIT = 2500; + 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 BASE_MODULES = of( new YangBindingProviderModule(), @@ -79,6 +88,10 @@ public class BaseMinimalDistributionTest { new NetconfModule(), new NetconfReadersModule(), new RestconfModule(), + new BgpModule(), + new BgpExtensionsModule(), + new BgpReadersModule(), + new BgpWritersModule(), new CfgAttrsModule()); @Before @@ -111,13 +124,15 @@ public class BaseMinimalDistributionTest { assertRestconfHttp(); LOG.info("Testing RESTCONF HTTPS"); assertRestconfHttps(); + LOG.info("Testing BGP"); + assertBgp(); } private void assertNetconfTcp() throws Exception { try (final Socket localhost = new Socket("127.0.0.1", NETCONF_TCP_PORT); final InputStream inputStream = localhost.getInputStream()) { // Wait until hello msg is sent from server - Thread.sleep(NETCONF_HELLO_WAIT); + Thread.sleep(HELLO_WAIT); final String helloMessage = inputStreamToString(inputStream); LOG.info("NETCONF TCP sent hello: {}", helloMessage); @@ -127,11 +142,14 @@ public class BaseMinimalDistributionTest { } } - private String inputStreamToString(final InputStream inputStream) throws IOException { + private byte[] readMessage(final InputStream inputStream) throws IOException { final int available = inputStream.available(); - final byte[] helloBytes = new byte[available]; - ByteStreams.read(inputStream, helloBytes, 0, available); - return new String(helloBytes, Charsets.UTF_8); + final byte[] msg = new byte[available]; + ByteStreams.read(inputStream, msg, 0, available); + return msg; + } + private String inputStreamToString(final InputStream inputStream) throws IOException { + return new String(readMessage(inputStream), Charsets.UTF_8); } private void assertNetconfSsh() throws Exception { @@ -151,7 +169,7 @@ public class BaseMinimalDistributionTest { channel.connect(20000); // Wait until hello msg is sent from server - Thread.sleep(NETCONF_HELLO_WAIT); + Thread.sleep(HELLO_WAIT); final String helloMessage = inputStreamToString(inputStream); LOG.info("NETCONF SSH sent hello: {}", helloMessage); @@ -199,4 +217,19 @@ public class BaseMinimalDistributionTest { 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 -- cgit 1.2.3-korg