package main
import (
- "context"
"fmt"
"os"
"github.com/edwarnicke/exechelper"
)
-func testProxyHttpTcp(s *NsSuite, dockerInstance, action string, proxySetup func() error) error {
+func testProxyHttpTcp(s *NsSuite, proto string) error {
const outputFile = "test.data"
const srcFile = "10M"
stopServer := make(chan struct{}, 1)
serverRunning := make(chan struct{}, 1)
- volumeArgs := fmt.Sprintf("-v shared-vol:/tmp/%s", dockerInstance)
- s.assertNil(dockerRun(dockerInstance, volumeArgs), "failed to start container")
- defer func() { exechelper.Run("docker stop " + dockerInstance) }()
-
- // start & configure vpp in the container
- _, err := hstExec(action, dockerInstance)
- s.assertNil(err)
-
- fmt.Println("VPP running and configured...")
-
- s.assertNil(proxySetup(), "failed to setup proxy")
- fmt.Println("Proxy configured...")
-
// create test file
- err = exechelper.Run(fmt.Sprintf("ip netns exec server truncate -s %s %s", srcFile, srcFile))
+ err := exechelper.Run(fmt.Sprintf("ip netns exec server truncate -s %s %s", srcFile, srcFile))
s.assertNil(err, "failed to run truncate command")
defer func() { os.Remove(srcFile) }()
- fmt.Println("Test file created...")
+ s.log("test file created...")
- go startHttpServer(serverRunning, stopServer, ":666", "server")
+ go s.startHttpServer(serverRunning, stopServer, ":666", "server")
// TODO better error handling and recovery
<-serverRunning
stopServer <- struct{}{}
}(stopServer)
- fmt.Println("http server started...")
+ s.log("http server started...")
- c := fmt.Sprintf("ip netns exec client wget --retry-connrefused --retry-on-http-error=503 --tries=10 -O %s 10.0.0.2:555/%s", outputFile, srcFile)
+ clientVeth := s.netInterfaces[clientInterface]
+ c := fmt.Sprintf("ip netns exec client wget --no-proxy --retry-connrefused"+
+ " --retry-on-http-error=503 --tries=10 -O %s ", outputFile)
+ if proto == "tls" {
+ c += " --secure-protocol=TLSv1_3 --no-check-certificate https://"
+ }
+ c += fmt.Sprintf("%s:555/%s", clientVeth.ip4AddressString(), srcFile)
+ s.log(c)
_, err = exechelper.CombinedOutput(c)
s.assertNil(err, "failed to run wget")
stopServer <- struct{}{}
return nil
}
-func setupEnvoy(ctx context.Context, dockerInstance string) error {
- errCh := startEnvoy(ctx, dockerInstance)
- select {
- case err := <-errCh:
- return err
- default:
- }
-
- go func(ctx context.Context, errCh <-chan error) {
- for {
- select {
- // handle cancel() call from outside to gracefully stop the routine
- case <-ctx.Done():
- return
- default:
- select {
- case err := <-errCh:
- fmt.Printf("error while running envoy: %v", err)
- default:
- }
- }
- }
- }(ctx, errCh)
- return nil
+func configureVppProxy(s *NsSuite, proto string) {
+ serverVeth := s.netInterfaces[serverInterface]
+ clientVeth := s.netInterfaces[clientInterface]
+
+ testVppProxy := s.getContainerByName("vpp").vppInstance
+ output := testVppProxy.vppctl(
+ "test proxy server server-uri %s://%s/555 client-uri tcp://%s/666",
+ proto,
+ clientVeth.ip4AddressString(),
+ serverVeth.peer.ip4AddressString(),
+ )
+ s.log("proxy configured...", output)
}
func (s *NsSuite) TestVppProxyHttpTcp() {
- dockerInstance := "vpp-proxy"
- err := testProxyHttpTcp(s, dockerInstance, "ConfigureVppProxy", configureVppProxy)
+ proto := "tcp"
+ configureVppProxy(s, proto)
+ err := testProxyHttpTcp(s, proto)
s.assertNil(err)
}
-func (s *NsSuite) TestEnvoyProxyHttpTcp() {
- exechelper.Run("docker volume create --name=shared-vol")
- defer func() {
- exechelper.Run("docker stop envoy")
- }()
+func (s *NsSuite) TestVppProxyHttpTls() {
+ proto := "tls"
+ configureVppProxy(s, proto)
+ err := testProxyHttpTcp(s, proto)
+ s.assertNil(err)
+}
- ctx, cancel := context.WithCancel(context.Background())
+func configureEnvoyProxy(s *NsSuite) {
+ envoyContainer := s.getContainerByName("envoy")
+ envoyContainer.create()
- dockerInstance := "vpp-envoy"
- err := testProxyHttpTcp(s, dockerInstance, "ConfigureEnvoyProxy", func() error {
- return setupEnvoy(ctx, dockerInstance)
- })
+ serverVeth := s.netInterfaces[serverInterface]
+ address := struct {
+ Server string
+ }{
+ Server: serverVeth.peer.ip4AddressString(),
+ }
+ envoyContainer.createConfig(
+ "/etc/envoy/envoy.yaml",
+ "resources/envoy/proxy.yaml",
+ address,
+ )
+ s.assertNil(envoyContainer.start())
+}
+
+func (s *NsSuite) TestEnvoyProxyHttpTcp() {
+ configureEnvoyProxy(s)
+ err := testProxyHttpTcp(s, "tcp")
s.assertNil(err)
- cancel()
}