7 "github.com/edwarnicke/exechelper"
8 . "github.com/onsi/ginkgo/v2"
12 registerNsTests(VppProxyHttpTcpTest, VppProxyHttpTlsTest, EnvoyProxyHttpTcpTest)
15 func testProxyHttpTcp(s *NsSuite, proto string) error {
16 var outputFile string = "test" + s.pid + ".data"
17 var srcFilePid string = "httpTestFile" + s.pid
18 const srcFileNoPid = "httpTestFile"
19 const fileSize string = "10M"
20 stopServer := make(chan struct{}, 1)
21 serverRunning := make(chan struct{}, 1)
22 serverNetns := s.getNetNamespaceByName("srv")
23 clientNetns := s.getNetNamespaceByName("cln")
26 err := exechelper.Run(fmt.Sprintf("ip netns exec %s truncate -s %s %s", serverNetns, fileSize, srcFilePid))
27 s.assertNil(err, "failed to run truncate command: "+fmt.Sprint(err))
28 defer func() { os.Remove(srcFilePid) }()
30 s.log("test file created...")
34 s.startHttpServer(serverRunning, stopServer, ":666", serverNetns)
36 // TODO better error handling and recovery
39 defer func(chan struct{}) {
40 stopServer <- struct{}{}
43 s.log("http server started...")
45 clientVeth := s.getInterfaceByName(clientInterface)
46 c := fmt.Sprintf("ip netns exec %s wget --no-proxy --retry-connrefused"+
47 " --retry-on-http-error=503 --tries=10 -O %s ", clientNetns, outputFile)
49 c += " --secure-protocol=TLSv1_3 --no-check-certificate https://"
51 c += fmt.Sprintf("%s:555/%s", clientVeth.ip4AddressString(), srcFileNoPid)
53 _, err = exechelper.CombinedOutput(c)
55 defer func() { os.Remove(outputFile) }()
57 s.assertNil(err, "failed to run wget: '%s', cmd: %s", err, c)
58 stopServer <- struct{}{}
60 s.assertNil(assertFileSize(outputFile, srcFilePid))
64 func configureVppProxy(s *NsSuite, proto string) {
65 serverVeth := s.getInterfaceByName(serverInterface)
66 clientVeth := s.getInterfaceByName(clientInterface)
68 testVppProxy := s.getContainerByName("vpp").vppInstance
69 output := testVppProxy.vppctl(
70 "test proxy server server-uri %s://%s/555 client-uri tcp://%s/666",
72 clientVeth.ip4AddressString(),
73 serverVeth.peer.ip4AddressString(),
75 s.log("proxy configured: " + output)
78 func VppProxyHttpTcpTest(s *NsSuite) {
80 configureVppProxy(s, proto)
81 err := testProxyHttpTcp(s, proto)
82 s.assertNil(err, fmt.Sprint(err))
85 func VppProxyHttpTlsTest(s *NsSuite) {
87 configureVppProxy(s, proto)
88 err := testProxyHttpTcp(s, proto)
89 s.assertNil(err, fmt.Sprint(err))
92 func configureEnvoyProxy(s *NsSuite) {
93 envoyContainer := s.getContainerByName("envoy")
94 err := envoyContainer.create()
95 s.assertNil(err, "Error creating envoy container: %s", err)
97 serverVeth := s.getInterfaceByName(serverInterface)
101 Server: serverVeth.peer.ip4AddressString(),
103 envoyContainer.createConfig(
104 "/etc/envoy/envoy.yaml",
105 "resources/envoy/proxy.yaml",
108 s.assertNil(envoyContainer.start())
111 func EnvoyProxyHttpTcpTest(s *NsSuite) {
112 configureEnvoyProxy(s)
113 err := testProxyHttpTcp(s, "tcp")
114 s.assertNil(err, fmt.Sprint(err))