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" |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 5 | "strconv" |
| 6 | "time" |
Adrian Villin | 5a4c7a9 | 2024-09-26 11:24:34 +0200 | [diff] [blame] | 7 | |
| 8 | . "fd.io/hs-test/infra" |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 9 | . "github.com/onsi/ginkgo/v2" |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 10 | ) |
| 11 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 12 | func init() { |
Matus Fabian | afce287 | 2024-09-20 16:34:59 +0200 | [diff] [blame] | 13 | RegisterVppProxyTests(VppProxyHttpGetTcpTest, VppProxyHttpGetTlsTest, VppProxyHttpPutTcpTest, VppProxyHttpPutTlsTest, |
| 14 | VppConnectProxyGetTest, VppConnectProxyPutTest) |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 15 | RegisterVppProxySoloTests(VppProxyHttpGetTcpMTTest, VppProxyHttpPutTcpMTTest, VppProxyTcpIperfMTTest, VppProxyUdpIperfMTTest) |
Matus Fabian | aa488dd | 2024-11-15 12:32:07 +0100 | [diff] [blame] | 16 | RegisterVppUdpProxyTests(VppProxyUdpTest) |
Matus Fabian | 5b175ec | 2024-09-06 15:30:59 +0200 | [diff] [blame] | 17 | RegisterEnvoyProxyTests(EnvoyProxyHttpGetTcpTest, EnvoyProxyHttpPutTcpTest) |
Matus Fabian | 7301abe | 2024-08-21 17:25:41 +0200 | [diff] [blame] | 18 | RegisterNginxProxyTests(NginxMirroringTest) |
Adrian Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 19 | RegisterNginxProxySoloTests(MirrorMultiThreadTest) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 20 | } |
| 21 | |
Matus Fabian | 8792e5c | 2024-08-14 12:38:20 +0200 | [diff] [blame] | 22 | func configureVppProxy(s *VppProxySuite, proto string, proxyPort uint16) { |
Adrian Villin | af5fcbf | 2024-12-09 14:18:31 +0100 | [diff] [blame] | 23 | vppProxy := s.Containers.VppProxy.VppInstance |
Matus Fabian | afce287 | 2024-09-20 16:34:59 +0200 | [diff] [blame] | 24 | cmd := fmt.Sprintf("test proxy server fifo-size 512k server-uri %s://%s/%d", proto, s.VppProxyAddr(), proxyPort) |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 25 | if proto != "http" && proto != "udp" { |
| 26 | proto = "tcp" |
Matus Fabian | afce287 | 2024-09-20 16:34:59 +0200 | [diff] [blame] | 27 | } |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 28 | if proto != "http" { |
| 29 | cmd += fmt.Sprintf(" client-uri %s://%s/%d", proto, s.ServerAddr(), s.ServerPort()) |
| 30 | } |
| 31 | |
Matus Fabian | afce287 | 2024-09-20 16:34:59 +0200 | [diff] [blame] | 32 | output := vppProxy.Vppctl(cmd) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 33 | s.Log("proxy configured: " + output) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Adrian Villin | d05f16d | 2024-11-20 11:11:35 +0100 | [diff] [blame] | 36 | func VppProxyHttpGetTcpMTTest(s *VppProxySuite) { |
| 37 | VppProxyHttpGetTcpTest(s) |
| 38 | } |
| 39 | |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 40 | func VppProxyTcpIperfMTTest(s *VppProxySuite) { |
| 41 | vppProxyIperfMTTest(s, "tcp") |
| 42 | } |
| 43 | |
| 44 | func VppProxyUdpIperfMTTest(s *VppProxySuite) { |
| 45 | vppProxyIperfMTTest(s, "udp") |
| 46 | } |
| 47 | |
| 48 | func vppProxyIperfMTTest(s *VppProxySuite, proto string) { |
Adrian Villin | af5fcbf | 2024-12-09 14:18:31 +0100 | [diff] [blame] | 49 | s.Containers.IperfC.Run() |
| 50 | s.Containers.IperfS.Run() |
| 51 | vppProxy := s.Containers.VppProxy.VppInstance |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 52 | proxyPort, err := strconv.Atoi(s.GetPortFromPpid()) |
| 53 | s.AssertNil(err) |
| 54 | |
| 55 | // tap interfaces are created on test setup with 1 rx-queue, |
| 56 | // need to recreate them with 2 + consistent-qp |
Adrian Villin | af5fcbf | 2024-12-09 14:18:31 +0100 | [diff] [blame] | 57 | s.AssertNil(vppProxy.DeleteTap(s.Interfaces.Server)) |
| 58 | s.AssertNil(vppProxy.CreateTap(s.Interfaces.Server, 2, uint32(s.Interfaces.Server.Peer.Index), Consistent_qp)) |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 59 | |
Adrian Villin | af5fcbf | 2024-12-09 14:18:31 +0100 | [diff] [blame] | 60 | s.AssertNil(vppProxy.DeleteTap(s.Interfaces.Client)) |
| 61 | s.AssertNil(vppProxy.CreateTap(s.Interfaces.Client, 2, uint32(s.Interfaces.Client.Peer.Index), Consistent_qp)) |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 62 | |
| 63 | configureVppProxy(s, "tcp", uint16(proxyPort)) |
| 64 | if proto == "udp" { |
| 65 | configureVppProxy(s, "udp", uint16(proxyPort)) |
| 66 | proto = "-u" |
| 67 | } else { |
| 68 | proto = "" |
| 69 | } |
| 70 | |
| 71 | stopServerCh := make(chan struct{}, 1) |
| 72 | srvCh := make(chan error, 1) |
| 73 | clnCh := make(chan error) |
| 74 | clnRes := make(chan []byte, 1) |
| 75 | |
| 76 | defer func() { |
| 77 | stopServerCh <- struct{}{} |
| 78 | }() |
| 79 | |
| 80 | go func() { |
| 81 | defer GinkgoRecover() |
| 82 | cmd := fmt.Sprintf("iperf3 -4 -s -B %s -p %s", s.ServerAddr(), fmt.Sprint(s.ServerPort())) |
Adrian Villin | af5fcbf | 2024-12-09 14:18:31 +0100 | [diff] [blame] | 83 | s.StartServerApp(s.Containers.IperfS, "iperf3", cmd, srvCh, stopServerCh) |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 84 | }() |
| 85 | |
| 86 | err = <-srvCh |
| 87 | s.AssertNil(err, fmt.Sprint(err)) |
| 88 | |
| 89 | go func() { |
| 90 | defer GinkgoRecover() |
| 91 | cmd := fmt.Sprintf("iperf3 -c %s -P 4 -l 1460 -b 10g -J -p %d -B %s %s", s.VppProxyAddr(), proxyPort, s.ClientAddr(), proto) |
Adrian Villin | af5fcbf | 2024-12-09 14:18:31 +0100 | [diff] [blame] | 92 | s.StartClientApp(s.Containers.IperfC, cmd, clnCh, clnRes) |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 93 | }() |
| 94 | |
| 95 | s.AssertChannelClosed(time.Minute*4, clnCh) |
| 96 | result := s.ParseJsonIperfOutput(<-clnRes) |
| 97 | s.LogJsonIperfOutput(result) |
| 98 | s.AssertIperfMinTransfer(result, 400) |
| 99 | } |
| 100 | |
Matus Fabian | 5b175ec | 2024-09-06 15:30:59 +0200 | [diff] [blame] | 101 | func VppProxyHttpGetTcpTest(s *VppProxySuite) { |
Matus Fabian | 8792e5c | 2024-08-14 12:38:20 +0200 | [diff] [blame] | 102 | var proxyPort uint16 = 8080 |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 103 | s.SetupNginxServer() |
Matus Fabian | 8792e5c | 2024-08-14 12:38:20 +0200 | [diff] [blame] | 104 | configureVppProxy(s, "tcp", proxyPort) |
| 105 | uri := fmt.Sprintf("http://%s:%d/httpTestFile", s.VppProxyAddr(), proxyPort) |
| 106 | s.CurlDownloadResource(uri) |
Filip Tehlar | 3336eef | 2023-11-29 07:40:18 +0100 | [diff] [blame] | 107 | } |
| 108 | |
Matus Fabian | 5b175ec | 2024-09-06 15:30:59 +0200 | [diff] [blame] | 109 | func VppProxyHttpGetTlsTest(s *VppProxySuite) { |
Matus Fabian | 8792e5c | 2024-08-14 12:38:20 +0200 | [diff] [blame] | 110 | var proxyPort uint16 = 8080 |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 111 | s.SetupNginxServer() |
Matus Fabian | 8792e5c | 2024-08-14 12:38:20 +0200 | [diff] [blame] | 112 | configureVppProxy(s, "tls", proxyPort) |
| 113 | uri := fmt.Sprintf("https://%s:%d/httpTestFile", s.VppProxyAddr(), proxyPort) |
| 114 | s.CurlDownloadResource(uri) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Adrian Villin | d05f16d | 2024-11-20 11:11:35 +0100 | [diff] [blame] | 117 | func VppProxyHttpPutTcpMTTest(s *VppProxySuite) { |
| 118 | VppProxyHttpPutTcpTest(s) |
| 119 | } |
| 120 | |
Matus Fabian | 5b175ec | 2024-09-06 15:30:59 +0200 | [diff] [blame] | 121 | func VppProxyHttpPutTcpTest(s *VppProxySuite) { |
| 122 | var proxyPort uint16 = 8080 |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 123 | s.SetupNginxServer() |
Matus Fabian | 5b175ec | 2024-09-06 15:30:59 +0200 | [diff] [blame] | 124 | configureVppProxy(s, "tcp", proxyPort) |
| 125 | uri := fmt.Sprintf("http://%s:%d/upload/testFile", s.VppProxyAddr(), proxyPort) |
| 126 | s.CurlUploadResource(uri, CurlContainerTestFile) |
| 127 | } |
| 128 | |
| 129 | func VppProxyHttpPutTlsTest(s *VppProxySuite) { |
| 130 | var proxyPort uint16 = 8080 |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 131 | s.SetupNginxServer() |
Matus Fabian | 5b175ec | 2024-09-06 15:30:59 +0200 | [diff] [blame] | 132 | configureVppProxy(s, "tls", proxyPort) |
| 133 | uri := fmt.Sprintf("https://%s:%d/upload/testFile", s.VppProxyAddr(), proxyPort) |
| 134 | s.CurlUploadResource(uri, CurlContainerTestFile) |
| 135 | } |
| 136 | |
| 137 | func EnvoyProxyHttpGetTcpTest(s *EnvoyProxySuite) { |
Matus Fabian | 8792e5c | 2024-08-14 12:38:20 +0200 | [diff] [blame] | 138 | uri := fmt.Sprintf("http://%s:%d/httpTestFile", s.ProxyAddr(), s.ProxyPort()) |
| 139 | s.CurlDownloadResource(uri) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 140 | } |
Matus Fabian | 7301abe | 2024-08-21 17:25:41 +0200 | [diff] [blame] | 141 | |
Matus Fabian | 5b175ec | 2024-09-06 15:30:59 +0200 | [diff] [blame] | 142 | func EnvoyProxyHttpPutTcpTest(s *EnvoyProxySuite) { |
| 143 | uri := fmt.Sprintf("http://%s:%d/upload/testFile", s.ProxyAddr(), s.ProxyPort()) |
| 144 | s.CurlUploadResource(uri, CurlContainerTestFile) |
| 145 | } |
| 146 | |
Adrian Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 147 | func MirrorMultiThreadTest(s *NginxProxySuite) { |
| 148 | nginxMirroring(s, true) |
| 149 | } |
| 150 | |
Matus Fabian | 7301abe | 2024-08-21 17:25:41 +0200 | [diff] [blame] | 151 | func NginxMirroringTest(s *NginxProxySuite) { |
Adrian Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 152 | nginxMirroring(s, false) |
| 153 | } |
| 154 | |
| 155 | func nginxMirroring(s *NginxProxySuite, multiThreadWorkers bool) { |
Adrian Villin | af5fcbf | 2024-12-09 14:18:31 +0100 | [diff] [blame] | 156 | vpp := s.Containers.Vpp.VppInstance |
Adrian Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 157 | |
Adrian Villin | af5fcbf | 2024-12-09 14:18:31 +0100 | [diff] [blame] | 158 | s.AddVclConfig(s.Containers.NginxProxy, multiThreadWorkers) |
| 159 | s.CreateNginxProxyConfig(s.Containers.NginxProxy, multiThreadWorkers) |
| 160 | s.Containers.NginxProxy.Start() |
Adrian Villin | 46ab0b2 | 2024-09-19 17:19:39 +0200 | [diff] [blame] | 161 | vpp.WaitForApp("nginx-", 5) |
Matus Fabian | 7301abe | 2024-08-21 17:25:41 +0200 | [diff] [blame] | 162 | uri := fmt.Sprintf("http://%s:%d/httpTestFile", s.ProxyAddr(), s.ProxyPort()) |
| 163 | s.CurlDownloadResource(uri) |
| 164 | } |
Matus Fabian | afce287 | 2024-09-20 16:34:59 +0200 | [diff] [blame] | 165 | |
| 166 | func VppConnectProxyGetTest(s *VppProxySuite) { |
| 167 | var proxyPort uint16 = 8080 |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 168 | s.SetupNginxServer() |
Matus Fabian | afce287 | 2024-09-20 16:34:59 +0200 | [diff] [blame] | 169 | configureVppProxy(s, "http", proxyPort) |
| 170 | |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 171 | targetUri := fmt.Sprintf("http://%s:%d/httpTestFile", s.ServerAddr(), s.ServerPort()) |
Matus Fabian | afce287 | 2024-09-20 16:34:59 +0200 | [diff] [blame] | 172 | proxyUri := fmt.Sprintf("http://%s:%d", s.VppProxyAddr(), proxyPort) |
| 173 | s.CurlDownloadResourceViaTunnel(targetUri, proxyUri) |
| 174 | } |
| 175 | |
| 176 | func VppConnectProxyPutTest(s *VppProxySuite) { |
| 177 | var proxyPort uint16 = 8080 |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 178 | s.SetupNginxServer() |
Matus Fabian | afce287 | 2024-09-20 16:34:59 +0200 | [diff] [blame] | 179 | configureVppProxy(s, "http", proxyPort) |
| 180 | |
| 181 | proxyUri := fmt.Sprintf("http://%s:%d", s.VppProxyAddr(), proxyPort) |
Adrian Villin | dd02eb8 | 2024-11-29 16:33:14 +0100 | [diff] [blame] | 182 | targetUri := fmt.Sprintf("http://%s:%d/upload/testFile", s.ServerAddr(), s.ServerPort()) |
Matus Fabian | afce287 | 2024-09-20 16:34:59 +0200 | [diff] [blame] | 183 | s.CurlUploadResourceViaTunnel(targetUri, proxyUri, CurlContainerTestFile) |
| 184 | } |
Matus Fabian | aa488dd | 2024-11-15 12:32:07 +0100 | [diff] [blame] | 185 | |
| 186 | func VppProxyUdpTest(s *VppUdpProxySuite) { |
| 187 | remoteServerConn := s.StartEchoServer() |
| 188 | defer remoteServerConn.Close() |
| 189 | |
Adrian Villin | af5fcbf | 2024-12-09 14:18:31 +0100 | [diff] [blame] | 190 | vppProxy := s.Containers.VppProxy.VppInstance |
Matus Fabian | aa488dd | 2024-11-15 12:32:07 +0100 | [diff] [blame] | 191 | cmd := fmt.Sprintf("test proxy server fifo-size 512k server-uri udp://%s/%d", s.VppProxyAddr(), s.ProxyPort()) |
| 192 | cmd += fmt.Sprintf(" client-uri udp://%s/%d", s.ServerAddr(), s.ServerPort()) |
| 193 | s.Log(vppProxy.Vppctl(cmd)) |
| 194 | |
| 195 | b := make([]byte, 1500) |
| 196 | n, err := s.ClientSendReceive([]byte("hello"), b) |
| 197 | s.AssertNil(err, fmt.Sprint(err)) |
| 198 | s.AssertEqual([]byte("hello"), b[:n]) |
| 199 | } |