blob: f592426cf47dfa8187de02ff9751b7cab3dbac4c [file] [log] [blame]
Filip Tehlar229f5fc2022-08-09 14:44:47 +00001package main
2
3import (
Filip Tehlar229f5fc2022-08-09 14:44:47 +00004 "fmt"
5 "os"
Filip Tehlar229f5fc2022-08-09 14:44:47 +00006
7 "github.com/edwarnicke/exechelper"
8)
9
Filip Tehlarbb98aac2022-12-21 14:40:35 +010010func testProxyHttpTcp(s *NsSuite) error {
Filip Tehlar229f5fc2022-08-09 14:44:47 +000011 const outputFile = "test.data"
12 const srcFile = "10M"
13 stopServer := make(chan struct{}, 1)
14 serverRunning := make(chan struct{}, 1)
15
Filip Tehlar229f5fc2022-08-09 14:44:47 +000016 // create test file
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010017 err := exechelper.Run(fmt.Sprintf("ip netns exec server truncate -s %s %s", srcFile, srcFile))
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010018 s.assertNil(err, "failed to run truncate command")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000019 defer func() { os.Remove(srcFile) }()
20
Maros Ondrejicka87531802022-12-19 20:35:27 +010021 s.log("Test file created...")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000022
23 go startHttpServer(serverRunning, stopServer, ":666", "server")
24 // TODO better error handling and recovery
25 <-serverRunning
26
27 defer func(chan struct{}) {
28 stopServer <- struct{}{}
29 }(stopServer)
30
Maros Ondrejicka87531802022-12-19 20:35:27 +010031 s.log("http server started...")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000032
Filip Tehlar3f951432023-01-13 21:33:43 +010033 c := fmt.Sprintf("ip netns exec client wget --no-proxy --retry-connrefused --retry-on-http-error=503 --tries=10 -O %s 10.0.0.2:555/%s", outputFile, srcFile)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000034 _, err = exechelper.CombinedOutput(c)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010035 s.assertNil(err, "failed to run wget")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000036 stopServer <- struct{}{}
37
38 defer func() { os.Remove(outputFile) }()
39
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010040 s.assertNil(assertFileSize(outputFile, srcFile))
41 return nil
42}
43
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010044func configureVppProxy(s *NsSuite) error {
45 container := s.getContainerByName("vpp")
46 testVppProxy := NewVppInstance(container)
47 testVppProxy.setVppProxy()
48 err := testVppProxy.start()
49 s.assertNil(err, "failed to start and configure VPP")
Maros Ondrejicka87531802022-12-19 20:35:27 +010050 s.log("VPP running and configured...")
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010051
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010052 output, err := testVppProxy.vppctl("test proxy server server-uri tcp://10.0.0.2/555 client-uri tcp://10.0.1.1/666")
Maros Ondrejicka87531802022-12-19 20:35:27 +010053 s.log("Proxy configured...", string(output))
Filip Tehlarbb98aac2022-12-21 14:40:35 +010054 return err
Filip Tehlar229f5fc2022-08-09 14:44:47 +000055}
56
57func (s *NsSuite) TestVppProxyHttpTcp() {
Filip Tehlarbb98aac2022-12-21 14:40:35 +010058 err := configureVppProxy(s)
59 s.assertNil(err)
60 err = testProxyHttpTcp(s)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010061 s.assertNil(err)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000062}
63
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010064func configureEnvoyProxy(s *NsSuite) error {
65 vppContainer := s.getContainerByName("vpp")
66 testVppForEnvoyProxy := NewVppInstance(vppContainer)
67 testVppForEnvoyProxy.setEnvoyProxy()
68 err := testVppForEnvoyProxy.start()
69 s.assertNil(err, "failed to start and configure VPP")
70
71 envoyContainer := s.getContainerByName("envoy")
Filip Tehlarbb98aac2022-12-21 14:40:35 +010072 return envoyContainer.run()
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010073}
74
Filip Tehlar229f5fc2022-08-09 14:44:47 +000075func (s *NsSuite) TestEnvoyProxyHttpTcp() {
Filip Tehlarbb98aac2022-12-21 14:40:35 +010076 err := configureEnvoyProxy(s)
77 s.assertNil(err)
78 err = testProxyHttpTcp(s)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010079 s.assertNil(err)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000080}