Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 4 | "fmt" |
| 5 | "os" |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 6 | |
| 7 | "github.com/edwarnicke/exechelper" |
| 8 | ) |
| 9 | |
Filip Tehlar | bb98aac | 2022-12-21 14:40:35 +0100 | [diff] [blame] | 10 | func testProxyHttpTcp(s *NsSuite) error { |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 11 | const outputFile = "test.data" |
| 12 | const srcFile = "10M" |
| 13 | stopServer := make(chan struct{}, 1) |
| 14 | serverRunning := make(chan struct{}, 1) |
| 15 | |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 16 | // create test file |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 17 | err := exechelper.Run(fmt.Sprintf("ip netns exec server truncate -s %s %s", srcFile, srcFile)) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 18 | s.assertNil(err, "failed to run truncate command") |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 19 | defer func() { os.Remove(srcFile) }() |
| 20 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 21 | s.log("test file created...") |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 22 | |
| 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 Ondrejicka | 8753180 | 2022-12-19 20:35:27 +0100 | [diff] [blame] | 31 | s.log("http server started...") |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 32 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 33 | clientVeth := s.netInterfaces[clientInterface] |
| 34 | c := fmt.Sprintf("ip netns exec client wget --no-proxy --retry-connrefused"+ |
| 35 | " --retry-on-http-error=503 --tries=10"+ |
| 36 | " -O %s %s:555/%s", |
| 37 | outputFile, |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 38 | clientVeth.IP4AddressString(), |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 39 | srcFile, |
| 40 | ) |
| 41 | s.log(c) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 42 | _, err = exechelper.CombinedOutput(c) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 43 | s.assertNil(err, "failed to run wget") |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 44 | stopServer <- struct{}{} |
| 45 | |
| 46 | defer func() { os.Remove(outputFile) }() |
| 47 | |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 48 | s.assertNil(assertFileSize(outputFile, srcFile)) |
| 49 | return nil |
| 50 | } |
| 51 | |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 52 | func configureVppProxy(s *NsSuite) { |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 53 | serverVeth := s.netInterfaces[serverInterface] |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 54 | clientVeth := s.netInterfaces[clientInterface] |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 55 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 56 | testVppProxy := s.getContainerByName("vpp").vppInstance |
| 57 | output := testVppProxy.vppctl( |
| 58 | "test proxy server server-uri tcp://%s/555 client-uri tcp://%s/666", |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 59 | clientVeth.IP4AddressString(), |
Maros Ondrejicka | 40cba40 | 2023-02-23 13:19:15 +0100 | [diff] [blame] | 60 | serverVeth.Peer().IP4AddressString(), |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 61 | ) |
| 62 | s.log("proxy configured...", output) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | func (s *NsSuite) TestVppProxyHttpTcp() { |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 66 | configureVppProxy(s) |
| 67 | err := testProxyHttpTcp(s) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 68 | s.assertNil(err) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 71 | func configureEnvoyProxy(s *NsSuite) { |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 72 | envoyContainer := s.getContainerByName("envoy") |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 73 | envoyContainer.create() |
| 74 | |
| 75 | serverVeth := s.netInterfaces[serverInterface] |
| 76 | address := struct { |
| 77 | Server string |
| 78 | }{ |
| 79 | Server: serverVeth.Peer().IP4AddressString(), |
| 80 | } |
| 81 | envoyContainer.createConfig( |
| 82 | "/etc/envoy/envoy.yaml", |
| 83 | "resources/envoy/proxy.yaml", |
| 84 | address, |
| 85 | ) |
Filip Tehlar | 9abba11 | 2023-03-07 10:13:19 +0100 | [diff] [blame^] | 86 | s.assertNil(envoyContainer.start()) |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 87 | } |
| 88 | |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 89 | func (s *NsSuite) TestEnvoyProxyHttpTcp() { |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 90 | configureEnvoyProxy(s) |
| 91 | err := testProxyHttpTcp(s) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 92 | s.assertNil(err) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 93 | } |