diff options
author | Marek Gradzki <mgradzki@cisco.com> | 2017-07-13 10:41:27 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-07-17 08:16:43 +0000 |
commit | d2664a4f307a833e293b2dfbe44d9ab6579eef2d (patch) | |
tree | ea8d05794c7d110f7a15d18874678925db44e230 /infra/bgp-distribution-test | |
parent | a4a488f7cdd04498bfcda068bf171516a9afe4f0 (diff) |
HONEYCOMB-369: configurable BGP peers
BGP peer configuration is no longer read from bgp-peer.json file.
Netconf/Restconf is can be used instead.
BGP peer configuration in HC follows openconfig-extensions model (as in ODL BGP):
* http://docs.opendaylight.org/en/stable-boron/user-guide/bgp-user-guide.html#bgp-peering
* http://docs.opendaylight.org/en/stable-boron/user-guide/bgp-user-guide.html#bgp-application-peer-and-programmable-rib
Change-Id: I91aa6c4fc0923edbacf6cd10abd3957569a4f8c6
Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
(cherry picked from commit a3d562afdd96d4c37fe608af99f364e879ee92b6)
Diffstat (limited to 'infra/bgp-distribution-test')
3 files changed, 55 insertions, 11 deletions
diff --git a/infra/bgp-distribution-test/asciidoc/Readme.adoc b/infra/bgp-distribution-test/asciidoc/Readme.adoc index 25762d25f..9576a61b5 100644 --- a/infra/bgp-distribution-test/asciidoc/Readme.adoc +++ b/infra/bgp-distribution-test/asciidoc/Readme.adoc @@ -1,6 +1,6 @@ = bgp-distribution-test -Distribution tests use generated files(yang-module-index) +Distribution tests use generated files (yang-module-index) that are generated after the build phase that maven invoke unit test. Therefore these tests must be part or separate project that uses distribution -as dependency that has these files allready generated.
\ No newline at end of file +as dependency that has these files already generated.
\ No newline at end of file diff --git a/infra/bgp-distribution-test/src/test/java/io/fd/honeycomb/infra/bgp/distro/BgpDistributionTest.java b/infra/bgp-distribution-test/src/test/java/io/fd/honeycomb/infra/bgp/distro/BgpDistributionTest.java index a105b6532..d102f76b4 100644 --- a/infra/bgp-distribution-test/src/test/java/io/fd/honeycomb/infra/bgp/distro/BgpDistributionTest.java +++ b/infra/bgp-distribution-test/src/test/java/io/fd/honeycomb/infra/bgp/distro/BgpDistributionTest.java @@ -16,14 +16,21 @@ package io.fd.honeycomb.infra.bgp.distro; +import static org.junit.Assert.assertTrue; + +import com.google.common.base.Charsets; import com.google.common.io.ByteStreams; +import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; +import com.mashape.unirest.http.exceptions.UnirestException; import io.fd.honeycomb.infra.distro.Main; import io.fd.honeycomb.infra.distro.activation.ActivationModule; import java.io.IOException; import java.io.InputStream; import java.net.InetAddress; import java.net.Socket; +import java.nio.file.Files; +import java.nio.file.Paths; import javax.net.ssl.SSLContext; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.conn.ssl.TrustSelfSignedStrategy; @@ -37,6 +44,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class BgpDistributionTest { + private static final String BGP_HOST_ADDRESS = "127.0.0.1"; + private static final int HTTP_PORT = 8182; + private static final String UNAME = "admin"; + private static final String PASSWORD = "admin"; private static final Logger LOG = LoggerFactory.getLogger(BgpDistributionTest.class); private static final String CERT_PASSWORD = "testing"; @@ -67,18 +78,38 @@ public class BgpDistributionTest { 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"); + + configureBgpPeers(); + + assertBgpOpenIsSent("127.0.0.2"); + assertBgpOpenIsSent("127.0.0.3"); + } + + private void configureBgpPeers() throws UnirestException, IOException { + final String url = + "http://" + BGP_HOST_ADDRESS + ":" + HTTP_PORT + + "/restconf/config/openconfig-network-instance:network-instances/network-instance/global-bgp/" + + "openconfig-network-instance:protocols/protocol/openconfig-policy-types:BGP/hc-bgp-instance/" + + "bgp/bgp-openconfig-extensions:neighbors"; + + final String request = + new String(Files.readAllBytes(Paths.get("src/test/resources/bgp-peers.json")), Charsets.UTF_8); + final HttpResponse<String> response = + Unirest.put(url) + .basicAuth(UNAME, PASSWORD) + .header("Content-Type", "application/json") + .body(request) + .asString(); + + assertSuccessStatus(response); + } + + private void assertBgpOpenIsSent(final String peerAddress) throws IOException, InterruptedException { + final InetAddress bgpHost = InetAddress.getByName(BGP_HOST_ADDRESS); + final InetAddress bgpPeerAddress = InetAddress.getByName(peerAddress); try (final Socket localhost = new Socket(bgpHost, BGP_PORT, bgpPeerAddress, 0); final InputStream inputStream = localhost.getInputStream()) { // Wait until bgp message is sent @@ -90,4 +121,16 @@ public class BgpDistributionTest { Assert.assertEquals(BGP_OPEN_MSG_TYPE, msg[BGP_MSG_TYPE_OFFSET]); } } + + 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 assertSuccessStatus(final HttpResponse<String> jsonNodeHttpResponse) { + assertTrue(jsonNodeHttpResponse.getStatus() >= 200); + assertTrue(jsonNodeHttpResponse.getStatus() < 400); + } }
\ No newline at end of file diff --git a/infra/bgp-distribution-test/src/test/resources/bgp.json b/infra/bgp-distribution-test/src/test/resources/bgp.json index 5cc9a419c..82838ff43 100644 --- a/infra/bgp-distribution-test/src/test/resources/bgp.json +++ b/infra/bgp-distribution-test/src/test/resources/bgp.json @@ -4,6 +4,7 @@ "bgp-as-number": 65000, "bgp-receive-multiple-paths": "true", "bgp-send-max-paths": 0, + "bgp-network-instance-name": "global-bgp", "bgp-protocol-instance-name": "hc-bgp-instance", "bgp-netty-threads": 2 }
\ No newline at end of file |