2022-08-09 14:44:47 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/edwarnicke/exechelper"
|
|
|
|
)
|
|
|
|
|
2023-11-29 07:40:18 +01:00
|
|
|
func testProxyHttpTcp(s *NsSuite, proto string) error {
|
2024-02-13 06:00:02 -05:00
|
|
|
var outputFile string = "test" + s.pid + ".data"
|
|
|
|
var srcFilePid string = "httpTestFile" + s.pid
|
|
|
|
const srcFileNoPid = "httpTestFile"
|
|
|
|
const fileSize string = "10M"
|
2022-08-09 14:44:47 +00:00
|
|
|
stopServer := make(chan struct{}, 1)
|
|
|
|
serverRunning := make(chan struct{}, 1)
|
2024-02-13 06:00:02 -05:00
|
|
|
serverNetns := s.getNetNamespaceByName("srv")
|
|
|
|
clientNetns := s.getNetNamespaceByName("cln")
|
2022-08-09 14:44:47 +00:00
|
|
|
|
|
|
|
// create test file
|
2024-02-13 06:00:02 -05:00
|
|
|
err := exechelper.Run(fmt.Sprintf("ip netns exec %s truncate -s %s %s", serverNetns, fileSize, srcFilePid))
|
2024-02-12 02:44:53 -05:00
|
|
|
s.assertNil(err, "failed to run truncate command: " + fmt.Sprint(err))
|
2024-02-13 06:00:02 -05:00
|
|
|
defer func() { os.Remove(srcFilePid) }()
|
2022-08-09 14:44:47 +00:00
|
|
|
|
2023-02-02 08:58:04 +01:00
|
|
|
s.log("test file created...")
|
2022-08-09 14:44:47 +00:00
|
|
|
|
2024-02-13 03:26:25 -05:00
|
|
|
go s.startHttpServer(serverRunning, stopServer, ":666", serverNetns)
|
2022-08-09 14:44:47 +00:00
|
|
|
// TODO better error handling and recovery
|
|
|
|
<-serverRunning
|
|
|
|
|
|
|
|
defer func(chan struct{}) {
|
|
|
|
stopServer <- struct{}{}
|
|
|
|
}(stopServer)
|
|
|
|
|
2022-12-19 20:35:27 +01:00
|
|
|
s.log("http server started...")
|
2022-08-09 14:44:47 +00:00
|
|
|
|
2024-02-13 06:00:02 -05: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-02-13 06:00:02 -05:00
|
|
|
c += fmt.Sprintf("%s:555/%s", clientVeth.ip4AddressString(), srcFileNoPid)
|
2023-02-02 08:58:04 +01:00
|
|
|
s.log(c)
|
2022-08-09 14:44:47 +00:00
|
|
|
_, err = exechelper.CombinedOutput(c)
|
|
|
|
|
|
|
|
defer func() { os.Remove(outputFile) }()
|
|
|
|
|
2024-02-13 03:26:25 -05:00
|
|
|
s.assertNil(err, "failed to run wget: '%s', cmd: %s", err, c)
|
|
|
|
stopServer <- struct{}{}
|
|
|
|
|
2024-02-13 06:00:02 -05:00
|
|
|
s.assertNil(assertFileSize(outputFile, srcFilePid))
|
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-02-13 06:00:02 -05:00
|
|
|
serverVeth := s.getInterfaceByName(serverInterface)
|
|
|
|
clientVeth := s.getInterfaceByName(clientInterface)
|
2023-02-02 08:58:04 +01: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,
|
2023-02-28 16:55:01 +01:00
|
|
|
clientVeth.ip4AddressString(),
|
|
|
|
serverVeth.peer.ip4AddressString(),
|
2023-02-02 08:58:04 +01:00
|
|
|
)
|
|
|
|
s.log("proxy configured...", output)
|
2022-08-09 14:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *NsSuite) TestVppProxyHttpTcp() {
|
2023-11-29 07:40:18 +01:00
|
|
|
proto := "tcp"
|
|
|
|
configureVppProxy(s, proto)
|
|
|
|
err := testProxyHttpTcp(s, proto)
|
2024-02-12 02:44:53 -05:00
|
|
|
s.assertNil(err, err)
|
2023-11-29 07:40:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *NsSuite) TestVppProxyHttpTls() {
|
|
|
|
proto := "tls"
|
|
|
|
configureVppProxy(s, proto)
|
|
|
|
err := testProxyHttpTcp(s, proto)
|
2024-02-12 02:44:53 -05:00
|
|
|
s.assertNil(err, err)
|
2022-08-09 14:44:47 +00:00
|
|
|
}
|
|
|
|
|
2023-02-28 12:49:43 +01:00
|
|
|
func configureEnvoyProxy(s *NsSuite) {
|
2022-12-14 16:30:04 +01:00
|
|
|
envoyContainer := s.getContainerByName("envoy")
|
2024-02-12 02:44:53 -05:00
|
|
|
err := envoyContainer.create()
|
|
|
|
s.assertNil(err, "Error creating envoy container: %s", err)
|
2023-02-28 12:49:43 +01:00
|
|
|
|
2024-02-13 06:00:02 -05:00
|
|
|
serverVeth := s.getInterfaceByName(serverInterface)
|
2023-02-28 12:49:43 +01:00
|
|
|
address := struct {
|
|
|
|
Server string
|
|
|
|
}{
|
2023-02-28 16:55:01 +01:00
|
|
|
Server: serverVeth.peer.ip4AddressString(),
|
2023-02-28 12:49:43 +01:00
|
|
|
}
|
|
|
|
envoyContainer.createConfig(
|
|
|
|
"/etc/envoy/envoy.yaml",
|
|
|
|
"resources/envoy/proxy.yaml",
|
|
|
|
address,
|
|
|
|
)
|
2023-03-07 10:13:19 +01:00
|
|
|
s.assertNil(envoyContainer.start())
|
2022-12-14 16:30:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *NsSuite) TestEnvoyProxyHttpTcp() {
|
2023-02-28 12:49:43 +01:00
|
|
|
configureEnvoyProxy(s)
|
2023-11-29 07:40:18 +01:00
|
|
|
err := testProxyHttpTcp(s, "tcp")
|
2024-02-12 02:44:53 -05:00
|
|
|
s.assertNil(err, err)
|
2022-08-09 14:44:47 +00:00
|
|
|
}
|