dpdk: xstats vecor stuck at 0 elements
[vpp.git] / extras / hs-test / proxy_test.go
1 package main
2
3 import (
4         . "fd.io/hs-test/infra"
5         "fmt"
6         "github.com/edwarnicke/exechelper"
7         . "github.com/onsi/ginkgo/v2"
8         "os"
9 )
10
11 func init() {
12         RegisterNsTests(VppProxyHttpTcpTest, VppProxyHttpTlsTest, EnvoyProxyHttpTcpTest)
13 }
14
15 func testProxyHttpTcp(s *NsSuite, proto string) error {
16         var outputFile string = s.ProcessIndex + "test" + s.Ppid + ".data"
17         var srcFilePpid string = s.ProcessIndex + "httpTestFile" + s.Ppid
18         const srcFileNoPpid = "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")
24
25         // create test file
26         err := exechelper.Run(fmt.Sprintf("ip netns exec %s truncate -s %s %s", serverNetns, fileSize, srcFilePpid))
27         s.AssertNil(err, "failed to run truncate command: "+fmt.Sprint(err))
28         defer func() { os.Remove(srcFilePpid) }()
29
30         s.Log("test file created...")
31
32         go func() {
33                 defer GinkgoRecover()
34                 s.StartHttpServer(serverRunning, stopServer, ":666", serverNetns)
35         }()
36         // TODO better error handling and recovery
37         <-serverRunning
38
39         defer func(chan struct{}) {
40                 stopServer <- struct{}{}
41         }(stopServer)
42
43         s.Log("http server started...")
44
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)
48         if proto == "tls" {
49                 c += " --secure-protocol=TLSv1_3 --no-check-certificate https://"
50         }
51         c += fmt.Sprintf("%s:555/%s", clientVeth.Ip4AddressString(), srcFileNoPpid)
52         s.Log(c)
53         _, err = exechelper.CombinedOutput(c)
54
55         defer func() { os.Remove(outputFile) }()
56
57         s.AssertNil(err, "failed to run wget: '%s', cmd: %s", err, c)
58         stopServer <- struct{}{}
59
60         s.AssertNil(AssertFileSize(outputFile, srcFilePpid))
61         return nil
62 }
63
64 func configureVppProxy(s *NsSuite, proto string) {
65         serverVeth := s.GetInterfaceByName(ServerInterface)
66         clientVeth := s.GetInterfaceByName(ClientInterface)
67
68         testVppProxy := s.GetContainerByName("vpp").VppInstance
69         output := testVppProxy.Vppctl(
70                 "test proxy server server-uri %s://%s/555 client-uri tcp://%s/666",
71                 proto,
72                 clientVeth.Ip4AddressString(),
73                 serverVeth.Peer.Ip4AddressString(),
74         )
75         s.Log("proxy configured: " + output)
76 }
77
78 func VppProxyHttpTcpTest(s *NsSuite) {
79         proto := "tcp"
80         configureVppProxy(s, proto)
81         err := testProxyHttpTcp(s, proto)
82         s.AssertNil(err, fmt.Sprint(err))
83 }
84
85 func VppProxyHttpTlsTest(s *NsSuite) {
86         proto := "tls"
87         configureVppProxy(s, proto)
88         err := testProxyHttpTcp(s, proto)
89         s.AssertNil(err, fmt.Sprint(err))
90 }
91
92 func configureEnvoyProxy(s *NsSuite) {
93         envoyContainer := s.GetContainerByName("envoy")
94         err := envoyContainer.Create()
95         s.AssertNil(err, "Error creating envoy container: %s", err)
96
97         serverVeth := s.GetInterfaceByName(ServerInterface)
98         address := struct {
99                 Server string
100         }{
101                 Server: serverVeth.Peer.Ip4AddressString(),
102         }
103         envoyContainer.CreateConfig(
104                 "/etc/envoy/envoy.yaml",
105                 "resources/envoy/proxy.yaml",
106                 address,
107         )
108         s.AssertNil(envoyContainer.Start())
109 }
110
111 func EnvoyProxyHttpTcpTest(s *NsSuite) {
112         configureEnvoyProxy(s)
113         err := testProxyHttpTcp(s, "tcp")
114         s.AssertNil(err, fmt.Sprint(err))
115 }