blob: 0d1aa3b83cd571d3e307cadf7acea54d9898c337 [file] [log] [blame]
Filip Tehlar229f5fc2022-08-09 14:44:47 +00001package main
2
3import (
Filip Tehlar229f5fc2022-08-09 14:44:47 +00004 "fmt"
Adrian Villindd02eb82024-11-29 16:33:14 +01005 "strconv"
6 "time"
Adrian Villin5a4c7a92024-09-26 11:24:34 +02007
8 . "fd.io/hs-test/infra"
Adrian Villindd02eb82024-11-29 16:33:14 +01009 . "github.com/onsi/ginkgo/v2"
Filip Tehlar229f5fc2022-08-09 14:44:47 +000010)
11
Adrian Villincee15aa2024-03-14 11:42:55 -040012func init() {
Matus Fabianafce2872024-09-20 16:34:59 +020013 RegisterVppProxyTests(VppProxyHttpGetTcpTest, VppProxyHttpGetTlsTest, VppProxyHttpPutTcpTest, VppProxyHttpPutTlsTest,
14 VppConnectProxyGetTest, VppConnectProxyPutTest)
Adrian Villindd02eb82024-11-29 16:33:14 +010015 RegisterVppProxySoloTests(VppProxyHttpGetTcpMTTest, VppProxyHttpPutTcpMTTest, VppProxyTcpIperfMTTest, VppProxyUdpIperfMTTest)
Matus Fabianaa488dd2024-11-15 12:32:07 +010016 RegisterVppUdpProxyTests(VppProxyUdpTest)
Matus Fabian5b175ec2024-09-06 15:30:59 +020017 RegisterEnvoyProxyTests(EnvoyProxyHttpGetTcpTest, EnvoyProxyHttpPutTcpTest)
Matus Fabian7301abe2024-08-21 17:25:41 +020018 RegisterNginxProxyTests(NginxMirroringTest)
Adrian Villin46ab0b22024-09-19 17:19:39 +020019 RegisterNginxProxySoloTests(MirrorMultiThreadTest)
Adrian Villincee15aa2024-03-14 11:42:55 -040020}
21
Matus Fabian8792e5c2024-08-14 12:38:20 +020022func configureVppProxy(s *VppProxySuite, proto string, proxyPort uint16) {
Adrian Villinaf5fcbf2024-12-09 14:18:31 +010023 vppProxy := s.Containers.VppProxy.VppInstance
Matus Fabianafce2872024-09-20 16:34:59 +020024 cmd := fmt.Sprintf("test proxy server fifo-size 512k server-uri %s://%s/%d", proto, s.VppProxyAddr(), proxyPort)
Adrian Villindd02eb82024-11-29 16:33:14 +010025 if proto != "http" && proto != "udp" {
26 proto = "tcp"
Matus Fabianafce2872024-09-20 16:34:59 +020027 }
Adrian Villindd02eb82024-11-29 16:33:14 +010028 if proto != "http" {
29 cmd += fmt.Sprintf(" client-uri %s://%s/%d", proto, s.ServerAddr(), s.ServerPort())
30 }
31
Matus Fabianafce2872024-09-20 16:34:59 +020032 output := vppProxy.Vppctl(cmd)
Adrian Villin4677d922024-06-14 09:32:39 +020033 s.Log("proxy configured: " + output)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000034}
35
Adrian Villind05f16d2024-11-20 11:11:35 +010036func VppProxyHttpGetTcpMTTest(s *VppProxySuite) {
37 VppProxyHttpGetTcpTest(s)
38}
39
Adrian Villindd02eb82024-11-29 16:33:14 +010040func VppProxyTcpIperfMTTest(s *VppProxySuite) {
41 vppProxyIperfMTTest(s, "tcp")
42}
43
44func VppProxyUdpIperfMTTest(s *VppProxySuite) {
45 vppProxyIperfMTTest(s, "udp")
46}
47
48func vppProxyIperfMTTest(s *VppProxySuite, proto string) {
Adrian Villinaf5fcbf2024-12-09 14:18:31 +010049 s.Containers.IperfC.Run()
50 s.Containers.IperfS.Run()
51 vppProxy := s.Containers.VppProxy.VppInstance
Adrian Villindd02eb82024-11-29 16:33:14 +010052 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 Villinaf5fcbf2024-12-09 14:18:31 +010057 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 Villindd02eb82024-11-29 16:33:14 +010059
Adrian Villinaf5fcbf2024-12-09 14:18:31 +010060 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 Villindd02eb82024-11-29 16:33:14 +010062
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 Villinaf5fcbf2024-12-09 14:18:31 +010083 s.StartServerApp(s.Containers.IperfS, "iperf3", cmd, srvCh, stopServerCh)
Adrian Villindd02eb82024-11-29 16:33:14 +010084 }()
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 Villinaf5fcbf2024-12-09 14:18:31 +010092 s.StartClientApp(s.Containers.IperfC, cmd, clnCh, clnRes)
Adrian Villindd02eb82024-11-29 16:33:14 +010093 }()
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 Fabian5b175ec2024-09-06 15:30:59 +0200101func VppProxyHttpGetTcpTest(s *VppProxySuite) {
Matus Fabian8792e5c2024-08-14 12:38:20 +0200102 var proxyPort uint16 = 8080
Adrian Villindd02eb82024-11-29 16:33:14 +0100103 s.SetupNginxServer()
Matus Fabian8792e5c2024-08-14 12:38:20 +0200104 configureVppProxy(s, "tcp", proxyPort)
105 uri := fmt.Sprintf("http://%s:%d/httpTestFile", s.VppProxyAddr(), proxyPort)
106 s.CurlDownloadResource(uri)
Filip Tehlar3336eef2023-11-29 07:40:18 +0100107}
108
Matus Fabian5b175ec2024-09-06 15:30:59 +0200109func VppProxyHttpGetTlsTest(s *VppProxySuite) {
Matus Fabian8792e5c2024-08-14 12:38:20 +0200110 var proxyPort uint16 = 8080
Adrian Villindd02eb82024-11-29 16:33:14 +0100111 s.SetupNginxServer()
Matus Fabian8792e5c2024-08-14 12:38:20 +0200112 configureVppProxy(s, "tls", proxyPort)
113 uri := fmt.Sprintf("https://%s:%d/httpTestFile", s.VppProxyAddr(), proxyPort)
114 s.CurlDownloadResource(uri)
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000115}
116
Adrian Villind05f16d2024-11-20 11:11:35 +0100117func VppProxyHttpPutTcpMTTest(s *VppProxySuite) {
118 VppProxyHttpPutTcpTest(s)
119}
120
Matus Fabian5b175ec2024-09-06 15:30:59 +0200121func VppProxyHttpPutTcpTest(s *VppProxySuite) {
122 var proxyPort uint16 = 8080
Adrian Villindd02eb82024-11-29 16:33:14 +0100123 s.SetupNginxServer()
Matus Fabian5b175ec2024-09-06 15:30:59 +0200124 configureVppProxy(s, "tcp", proxyPort)
125 uri := fmt.Sprintf("http://%s:%d/upload/testFile", s.VppProxyAddr(), proxyPort)
126 s.CurlUploadResource(uri, CurlContainerTestFile)
127}
128
129func VppProxyHttpPutTlsTest(s *VppProxySuite) {
130 var proxyPort uint16 = 8080
Adrian Villindd02eb82024-11-29 16:33:14 +0100131 s.SetupNginxServer()
Matus Fabian5b175ec2024-09-06 15:30:59 +0200132 configureVppProxy(s, "tls", proxyPort)
133 uri := fmt.Sprintf("https://%s:%d/upload/testFile", s.VppProxyAddr(), proxyPort)
134 s.CurlUploadResource(uri, CurlContainerTestFile)
135}
136
137func EnvoyProxyHttpGetTcpTest(s *EnvoyProxySuite) {
Matus Fabian8792e5c2024-08-14 12:38:20 +0200138 uri := fmt.Sprintf("http://%s:%d/httpTestFile", s.ProxyAddr(), s.ProxyPort())
139 s.CurlDownloadResource(uri)
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000140}
Matus Fabian7301abe2024-08-21 17:25:41 +0200141
Matus Fabian5b175ec2024-09-06 15:30:59 +0200142func EnvoyProxyHttpPutTcpTest(s *EnvoyProxySuite) {
143 uri := fmt.Sprintf("http://%s:%d/upload/testFile", s.ProxyAddr(), s.ProxyPort())
144 s.CurlUploadResource(uri, CurlContainerTestFile)
145}
146
Adrian Villin46ab0b22024-09-19 17:19:39 +0200147func MirrorMultiThreadTest(s *NginxProxySuite) {
148 nginxMirroring(s, true)
149}
150
Matus Fabian7301abe2024-08-21 17:25:41 +0200151func NginxMirroringTest(s *NginxProxySuite) {
Adrian Villin46ab0b22024-09-19 17:19:39 +0200152 nginxMirroring(s, false)
153}
154
155func nginxMirroring(s *NginxProxySuite, multiThreadWorkers bool) {
Adrian Villinaf5fcbf2024-12-09 14:18:31 +0100156 vpp := s.Containers.Vpp.VppInstance
Adrian Villin46ab0b22024-09-19 17:19:39 +0200157
Adrian Villinaf5fcbf2024-12-09 14:18:31 +0100158 s.AddVclConfig(s.Containers.NginxProxy, multiThreadWorkers)
159 s.CreateNginxProxyConfig(s.Containers.NginxProxy, multiThreadWorkers)
160 s.Containers.NginxProxy.Start()
Adrian Villin46ab0b22024-09-19 17:19:39 +0200161 vpp.WaitForApp("nginx-", 5)
Matus Fabian7301abe2024-08-21 17:25:41 +0200162 uri := fmt.Sprintf("http://%s:%d/httpTestFile", s.ProxyAddr(), s.ProxyPort())
163 s.CurlDownloadResource(uri)
164}
Matus Fabianafce2872024-09-20 16:34:59 +0200165
166func VppConnectProxyGetTest(s *VppProxySuite) {
167 var proxyPort uint16 = 8080
Adrian Villindd02eb82024-11-29 16:33:14 +0100168 s.SetupNginxServer()
Matus Fabianafce2872024-09-20 16:34:59 +0200169 configureVppProxy(s, "http", proxyPort)
170
Adrian Villindd02eb82024-11-29 16:33:14 +0100171 targetUri := fmt.Sprintf("http://%s:%d/httpTestFile", s.ServerAddr(), s.ServerPort())
Matus Fabianafce2872024-09-20 16:34:59 +0200172 proxyUri := fmt.Sprintf("http://%s:%d", s.VppProxyAddr(), proxyPort)
173 s.CurlDownloadResourceViaTunnel(targetUri, proxyUri)
174}
175
176func VppConnectProxyPutTest(s *VppProxySuite) {
177 var proxyPort uint16 = 8080
Adrian Villindd02eb82024-11-29 16:33:14 +0100178 s.SetupNginxServer()
Matus Fabianafce2872024-09-20 16:34:59 +0200179 configureVppProxy(s, "http", proxyPort)
180
181 proxyUri := fmt.Sprintf("http://%s:%d", s.VppProxyAddr(), proxyPort)
Adrian Villindd02eb82024-11-29 16:33:14 +0100182 targetUri := fmt.Sprintf("http://%s:%d/upload/testFile", s.ServerAddr(), s.ServerPort())
Matus Fabianafce2872024-09-20 16:34:59 +0200183 s.CurlUploadResourceViaTunnel(targetUri, proxyUri, CurlContainerTestFile)
184}
Matus Fabianaa488dd2024-11-15 12:32:07 +0100185
186func VppProxyUdpTest(s *VppUdpProxySuite) {
187 remoteServerConn := s.StartEchoServer()
188 defer remoteServerConn.Close()
189
Adrian Villinaf5fcbf2024-12-09 14:18:31 +0100190 vppProxy := s.Containers.VppProxy.VppInstance
Matus Fabianaa488dd2024-11-15 12:32:07 +0100191 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}