4 . "fd.io/hs-test/infra"
6 "github.com/edwarnicke/exechelper"
7 . "github.com/onsi/ginkgo/v2"
12 RegisterNsTests(VppProxyHttpTcpTest, VppProxyHttpTlsTest, EnvoyProxyHttpTcpTest)
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")
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) }()
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(), srcFileNoPpid)
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, srcFilePpid))
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))