2022-08-09 14:44:47 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-06-14 09:32:39 +02:00
|
|
|
. "fd.io/hs-test/infra"
|
2022-08-09 14:44:47 +00:00
|
|
|
"fmt"
|
|
|
|
"github.com/edwarnicke/exechelper"
|
2024-03-14 11:42:55 -04:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
2024-06-14 09:32:39 +02:00
|
|
|
"os"
|
2022-08-09 14:44:47 +00:00
|
|
|
)
|
|
|
|
|
2024-03-14 11:42:55 -04:00
|
|
|
func init() {
|
2024-06-14 09:32:39 +02:00
|
|
|
RegisterNsTests(VppProxyHttpTcpTest, VppProxyHttpTlsTest, EnvoyProxyHttpTcpTest)
|
2024-03-14 11:42:55 -04:00
|
|
|
}
|
|
|
|
|
2023-11-29 07:40:18 +01:00
|
|
|
func testProxyHttpTcp(s *NsSuite, proto string) error {
|
2024-06-14 09:32:39 +02:00
|
|
|
var outputFile string = s.ProcessIndex + "test" + s.Ppid + ".data"
|
|
|
|
var srcFilePpid string = s.ProcessIndex + "httpTestFile" + s.Ppid
|
2024-06-06 04:26:30 -04:00
|
|
|
const srcFileNoPpid = "httpTestFile"
|
2024-02-13 06:00:02 -05:00
|
|
|
const fileSize string = "10M"
|
2022-08-09 14:44:47 +00:00
|
|
|
stopServer := make(chan struct{}, 1)
|
|
|
|
serverRunning := make(chan struct{}, 1)
|
2024-06-14 09:32:39 +02:00
|
|
|
serverNetns := s.GetNetNamespaceByName("srv")
|
|
|
|
clientNetns := s.GetNetNamespaceByName("cln")
|
2022-08-09 14:44:47 +00:00
|
|
|
|
|
|
|
// create test file
|
2024-06-06 04:26:30 -04:00
|
|
|
err := exechelper.Run(fmt.Sprintf("ip netns exec %s truncate -s %s %s", serverNetns, fileSize, srcFilePpid))
|
2024-06-14 09:32:39 +02:00
|
|
|
s.AssertNil(err, "failed to run truncate command: "+fmt.Sprint(err))
|
2024-06-06 04:26:30 -04:00
|
|
|
defer func() { os.Remove(srcFilePpid) }()
|
2022-08-09 14:44:47 +00:00
|
|
|
|
2024-06-14 09:32:39 +02:00
|
|
|
s.Log("test file created...")
|
2022-08-09 14:44:47 +00:00
|
|
|
|
2024-03-14 11:42:55 -04:00
|
|
|
go func() {
|
|
|
|
defer GinkgoRecover()
|
2024-06-14 09:32:39 +02:00
|
|
|
s.StartHttpServer(serverRunning, stopServer, ":666", serverNetns)
|
2024-03-14 11:42:55 -04:00
|
|
|
}()
|
2022-08-09 14:44:47 +00:00
|
|
|
// TODO better error handling and recovery
|
|
|
|
<-serverRunning
|
|
|
|
|
|
|
|
defer func(chan struct{}) {
|
|
|
|
stopServer <- struct{}{}
|
|
|
|
}(stopServer)
|
|
|
|
|
2024-06-14 09:32:39 +02:00
|
|
|
s.Log("http server started...")
|
2022-08-09 14:44:47 +00:00
|
|
|
|
2024-06-14 09:32:39 +02:00
|
|
|
clientVeth := s.GetInterfaceByName(ClientInterface)
|
2024-02-13 03:26:25 -05:00
|
|
|
c := fmt.Sprintf("ip netns exec %s wget --no-proxy --retry-connrefused"+
|
|
|
|
" --retry-on-http-error=503 --tries=10 -O %s ", clientNetns, outputFile)
|
2023-11-29 07:40:18 +01:00
|
|
|
if proto == "tls" {
|
|
|
|
c += " --secure-protocol=TLSv1_3 --no-check-certificate https://"
|
|
|
|
}
|
2024-06-14 09:32:39 +02:00
|
|
|
c += fmt.Sprintf("%s:555/%s", clientVeth.Ip4AddressString(), srcFileNoPpid)
|
|
|
|
s.Log(c)
|
2022-08-09 14:44:47 +00:00
|
|
|
_, err = exechelper.CombinedOutput(c)
|
|
|
|
|
|
|
|
defer func() { os.Remove(outputFile) }()
|
|
|
|
|
2024-06-14 09:32:39 +02:00
|
|
|
s.AssertNil(err, "failed to run wget: '%s', cmd: %s", err, c)
|
2024-02-13 03:26:25 -05:00
|
|
|
stopServer <- struct{}{}
|
|
|
|
|
2024-06-14 09:32:39 +02:00
|
|
|
s.AssertNil(AssertFileSize(outputFile, srcFilePpid))
|
2022-12-06 15:38:05 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-11-29 07:40:18 +01:00
|
|
|
func configureVppProxy(s *NsSuite, proto string) {
|
2024-06-14 09:32:39 +02:00
|
|
|
serverVeth := s.GetInterfaceByName(ServerInterface)
|
|
|
|
clientVeth := s.GetInterfaceByName(ClientInterface)
|
2023-02-02 08:58:04 +01:00
|
|
|
|
2024-06-14 09:32:39 +02:00
|
|
|
testVppProxy := s.GetContainerByName("vpp").VppInstance
|
|
|
|
output := testVppProxy.Vppctl(
|
2023-11-29 07:40:18 +01:00
|
|
|
"test proxy server server-uri %s://%s/555 client-uri tcp://%s/666",
|
|
|
|
proto,
|
2024-06-14 09:32:39 +02:00
|
|
|
clientVeth.Ip4AddressString(),
|
|
|
|
serverVeth.Peer.Ip4AddressString(),
|
2023-02-02 08:58:04 +01:00
|
|
|
)
|
2024-06-14 09:32:39 +02:00
|
|
|
s.Log("proxy configured: " + output)
|
2022-08-09 14:44:47 +00:00
|
|
|
}
|
|
|
|
|
2024-03-14 11:42:55 -04:00
|
|
|
func VppProxyHttpTcpTest(s *NsSuite) {
|
2023-11-29 07:40:18 +01:00
|
|
|
proto := "tcp"
|
|
|
|
configureVppProxy(s, proto)
|
|
|
|
err := testProxyHttpTcp(s, proto)
|
2024-06-14 09:32:39 +02:00
|
|
|
s.AssertNil(err, fmt.Sprint(err))
|
2023-11-29 07:40:18 +01:00
|
|
|
}
|
|
|
|
|
2024-03-14 11:42:55 -04:00
|
|
|
func VppProxyHttpTlsTest(s *NsSuite) {
|
2023-11-29 07:40:18 +01:00
|
|
|
proto := "tls"
|
|
|
|
configureVppProxy(s, proto)
|
|
|
|
err := testProxyHttpTcp(s, proto)
|
2024-06-14 09:32:39 +02:00
|
|
|
s.AssertNil(err, fmt.Sprint(err))
|
2022-08-09 14:44:47 +00:00
|
|
|
}
|
|
|
|
|
2023-02-28 12:49:43 +01:00
|
|
|
func configureEnvoyProxy(s *NsSuite) {
|
2024-06-14 09:32:39 +02:00
|
|
|
envoyContainer := s.GetContainerByName("envoy")
|
2024-07-09 15:31:36 +02:00
|
|
|
s.AssertNil(envoyContainer.Create())
|
2023-02-28 12:49:43 +01:00
|
|
|
|
2024-06-14 09:32:39 +02:00
|
|
|
serverVeth := s.GetInterfaceByName(ServerInterface)
|
2023-02-28 12:49:43 +01:00
|
|
|
address := struct {
|
|
|
|
Server string
|
|
|
|
}{
|
2024-06-14 09:32:39 +02:00
|
|
|
Server: serverVeth.Peer.Ip4AddressString(),
|
2023-02-28 12:49:43 +01:00
|
|
|
}
|
2024-06-14 09:32:39 +02:00
|
|
|
envoyContainer.CreateConfig(
|
2023-02-28 12:49:43 +01:00
|
|
|
"/etc/envoy/envoy.yaml",
|
|
|
|
"resources/envoy/proxy.yaml",
|
|
|
|
address,
|
|
|
|
)
|
2024-06-14 09:32:39 +02:00
|
|
|
s.AssertNil(envoyContainer.Start())
|
2022-12-14 16:30:04 +01:00
|
|
|
}
|
|
|
|
|
2024-03-14 11:42:55 -04:00
|
|
|
func EnvoyProxyHttpTcpTest(s *NsSuite) {
|
2023-02-28 12:49:43 +01:00
|
|
|
configureEnvoyProxy(s)
|
2023-11-29 07:40:18 +01:00
|
|
|
err := testProxyHttpTcp(s, "tcp")
|
2024-06-14 09:32:39 +02:00
|
|
|
s.AssertNil(err, fmt.Sprint(err))
|
2022-08-09 14:44:47 +00:00
|
|
|
}
|