blob: 4277d432e7204a4ff01a8474845ef8fbbbefc618 [file] [log] [blame]
Filip Tehlarb15a0002022-11-10 12:34:17 +01001package main
2
Filip Tehlarc204c872022-12-21 08:59:16 +01003import (
Filip Tehlar8df3de42023-01-27 13:14:34 +01004 "fmt"
Filip Tehlarc204c872022-12-21 08:59:16 +01005 "os"
Filip Tehlar58113562023-04-15 20:41:18 +02006 "strings"
Adrian Villincee15aa2024-03-14 11:42:55 -04007 "time"
8
9 . "github.com/onsi/ginkgo/v2"
Filip Tehlarc204c872022-12-21 08:59:16 +010010)
11
Adrian Villincee15aa2024-03-14 11:42:55 -040012func init() {
13 registerNsTests(HttpTpsTest)
14 registerVethTests(HttpCliTest)
15 registerNoTopoTests(NginxHttp3Test, NginxAsServerTest,
16 NginxPerfCpsTest, NginxPerfRpsTest, NginxPerfWrkTest)
17 registerNoTopoSoloTests(HttpStaticPromTest)
18}
19
20func HttpTpsTest(s *NsSuite) {
adrianvillin28bd8f02024-02-13 06:00:02 -050021 iface := s.getInterfaceByName(clientInterface)
Maros Ondrejickae7625d02023-02-28 16:55:01 +010022 client_ip := iface.ip4AddressString()
Filip Tehlarb15a0002022-11-10 12:34:17 +010023 port := "8080"
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010024 finished := make(chan error, 1)
adrianvillin28bd8f02024-02-13 06:00:02 -050025 clientNetns := s.getNetNamespaceByName("cln")
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010026
27 container := s.getContainerByName("vpp")
Filip Tehlarb15a0002022-11-10 12:34:17 +010028
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010029 // configure vpp in the container
30 container.vppInstance.vppctl("http tps uri tcp://0.0.0.0/8080")
Filip Tehlarb15a0002022-11-10 12:34:17 +010031
Adrian Villincee15aa2024-03-14 11:42:55 -040032 go func() {
33 defer GinkgoRecover()
34 s.startWget(finished, client_ip, port, "test_file_10M", clientNetns)
35 }()
Filip Tehlarb15a0002022-11-10 12:34:17 +010036 // wait for client
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010037 err := <-finished
Adrian Villincee15aa2024-03-14 11:42:55 -040038 s.assertNil(err, fmt.Sprint(err))
Filip Tehlarb15a0002022-11-10 12:34:17 +010039}
40
Adrian Villincee15aa2024-03-14 11:42:55 -040041func HttpCliTest(s *VethsSuite) {
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010042 serverContainer := s.getContainerByName("server-vpp")
43 clientContainer := s.getContainerByName("client-vpp")
Filip Tehlarb15a0002022-11-10 12:34:17 +010044
adrianvillin28bd8f02024-02-13 06:00:02 -050045 serverVeth := s.getInterfaceByName(serverInterfaceName)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010046
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010047 serverContainer.vppInstance.vppctl("http cli server")
Filip Tehlarb15a0002022-11-10 12:34:17 +010048
Maros Ondrejickae7625d02023-02-28 16:55:01 +010049 uri := "http://" + serverVeth.ip4AddressString() + "/80"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010050
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010051 o := clientContainer.vppInstance.vppctl("http cli client" +
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010052 " uri " + uri + " query /show/version")
Filip Tehlarb15a0002022-11-10 12:34:17 +010053
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010054 s.log(o)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010055 s.assertContains(o, "<html>", "<html> not found in the result!")
Filip Tehlarb15a0002022-11-10 12:34:17 +010056}
Filip Tehlarc204c872022-12-21 08:59:16 +010057
Adrian Villincee15aa2024-03-14 11:42:55 -040058func NginxHttp3Test(s *NoTopoSuite) {
Filip Tehlar31eaea92023-06-15 10:06:57 +020059 s.SkipUnlessExtendedTestsBuilt()
60
61 query := "index.html"
62 nginxCont := s.getContainerByName("nginx-http3")
63 s.assertNil(nginxCont.run())
64
65 vpp := s.getContainerByName("vpp").vppInstance
66 vpp.waitForApp("nginx-", 5)
adrianvillin28bd8f02024-02-13 06:00:02 -050067 serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString()
Filip Tehlar31eaea92023-06-15 10:06:57 +020068
69 defer func() { os.Remove(query) }()
70 curlCont := s.getContainerByName("curl")
Filip Tehlar87241fe2024-01-17 21:45:28 +010071 args := fmt.Sprintf("curl --noproxy '*' --local-port 55444 --http3-only -k https://%s:8443/%s", serverAddress, query)
Filip Tehlar31eaea92023-06-15 10:06:57 +020072 curlCont.extraRunningArgs = args
73 o, err := curlCont.combinedOutput()
Adrian Villincee15aa2024-03-14 11:42:55 -040074 s.assertNil(err, fmt.Sprint(err))
Filip Tehlar31eaea92023-06-15 10:06:57 +020075 s.assertContains(o, "<http>", "<http> not found in the result!")
76}
77
Adrian Villincee15aa2024-03-14 11:42:55 -040078func HttpStaticPromTest(s *NoTopoSuite) {
Filip Tehlarcc1475c2023-11-29 12:59:05 +010079 finished := make(chan error, 1)
80 query := "stats.prom"
81 vpp := s.getContainerByName("vpp").vppInstance
adrianvillin28bd8f02024-02-13 06:00:02 -050082 serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString()
Filip Tehlarcc1475c2023-11-29 12:59:05 +010083 s.log(vpp.vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers"))
84 s.log(vpp.vppctl("prom enable"))
Adrian Villincee15aa2024-03-14 11:42:55 -040085 time.Sleep(time.Second * 5)
86 go func() {
87 defer GinkgoRecover()
88 s.startWget(finished, serverAddress, "80", query, "")
89 }()
Filip Tehlarcc1475c2023-11-29 12:59:05 +010090 err := <-finished
Adrian Villincee15aa2024-03-14 11:42:55 -040091 s.assertNil(err)
Filip Tehlarcc1475c2023-11-29 12:59:05 +010092}
93
Adrian Villincee15aa2024-03-14 11:42:55 -040094func NginxAsServerTest(s *NoTopoSuite) {
Filip Tehlarc204c872022-12-21 08:59:16 +010095 query := "return_ok"
96 finished := make(chan error, 1)
Filip Tehlarc204c872022-12-21 08:59:16 +010097
98 nginxCont := s.getContainerByName("nginx")
99 s.assertNil(nginxCont.run())
100
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100101 vpp := s.getContainerByName("vpp").vppInstance
Florin Corase2415f72023-02-28 14:51:03 -0800102 vpp.waitForApp("nginx-", 5)
Filip Tehlarc204c872022-12-21 08:59:16 +0100103
adrianvillin28bd8f02024-02-13 06:00:02 -0500104 serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100105
Filip Tehlarc204c872022-12-21 08:59:16 +0100106 defer func() { os.Remove(query) }()
Adrian Villincee15aa2024-03-14 11:42:55 -0400107 go func() {
108 defer GinkgoRecover()
109 s.startWget(finished, serverAddress, "80", query, "")
110 }()
Filip Tehlarc204c872022-12-21 08:59:16 +0100111 s.assertNil(<-finished)
112}
Filip Tehlar8df3de42023-01-27 13:14:34 +0100113
Filip Tehlar58113562023-04-15 20:41:18 +0200114func parseString(s, pattern string) string {
115 temp := strings.Split(s, "\n")
116 for _, item := range temp {
117 if strings.Contains(item, pattern) {
118 return item
119 }
120 }
121 return ""
122}
123
Filip Tehlar8df3de42023-01-27 13:14:34 +0100124func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string) error {
125 nRequests := 1000000
Filip Tehlardda1f682023-04-24 17:52:50 +0200126 nClients := 1000
Filip Tehlar8df3de42023-01-27 13:14:34 +0100127
adrianvillin28bd8f02024-02-13 06:00:02 -0500128 serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100129
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100130 vpp := s.getContainerByName("vpp").vppInstance
Filip Tehlar8df3de42023-01-27 13:14:34 +0100131
adrianvillinfbf5f2b2024-02-13 03:26:25 -0500132 nginxCont := s.getContainerByName(singleTopoContainerNginx)
Filip Tehlar8df3de42023-01-27 13:14:34 +0100133 s.assertNil(nginxCont.run())
Florin Corase2415f72023-02-28 14:51:03 -0800134 vpp.waitForApp("nginx-", 5)
Filip Tehlar8df3de42023-01-27 13:14:34 +0100135
Filip Tehlarb41b0af2023-03-20 12:39:20 +0100136 if ab_or_wrk == "ab" {
137 abCont := s.getContainerByName("ab")
138 args := fmt.Sprintf("-n %d -c %d", nRequests, nClients)
139 if mode == "rps" {
140 args += " -k"
141 } else if mode != "cps" {
142 return fmt.Errorf("invalid mode %s; expected cps/rps", mode)
143 }
Filip Tehlardda1f682023-04-24 17:52:50 +0200144 // don't exit on socket receive errors
145 args += " -r"
Filip Tehlarb41b0af2023-03-20 12:39:20 +0100146 args += " http://" + serverAddress + ":80/64B.json"
147 abCont.extraRunningArgs = args
Adrian Villincee15aa2024-03-14 11:42:55 -0400148 time.Sleep(time.Second * 10)
Filip Tehlarb41b0af2023-03-20 12:39:20 +0100149 o, err := abCont.combinedOutput()
Filip Tehlar58113562023-04-15 20:41:18 +0200150 rps := parseString(o, "Requests per second:")
Adrian Villincee15aa2024-03-14 11:42:55 -0400151 s.log(rps)
152 s.log(err)
adrianvillin7c675472024-02-12 02:44:53 -0500153 s.assertNil(err, "err: '%s', output: '%s'", err, o)
Filip Tehlarb41b0af2023-03-20 12:39:20 +0100154 } else {
155 wrkCont := s.getContainerByName("wrk")
156 args := fmt.Sprintf("-c %d -t 2 -d 30 http://%s:80/64B.json", nClients,
157 serverAddress)
158 wrkCont.extraRunningArgs = args
159 o, err := wrkCont.combinedOutput()
Filip Tehlar58113562023-04-15 20:41:18 +0200160 rps := parseString(o, "requests")
Adrian Villincee15aa2024-03-14 11:42:55 -0400161 s.log(rps)
162 s.log(err)
adrianvillin7c675472024-02-12 02:44:53 -0500163 s.assertNil(err, "err: '%s', output: '%s'", err, o)
Filip Tehlarb41b0af2023-03-20 12:39:20 +0100164 }
Filip Tehlar8df3de42023-01-27 13:14:34 +0100165 return nil
166}
167
Adrian Villincee15aa2024-03-14 11:42:55 -0400168func NginxPerfCpsTest(s *NoTopoSuite) {
Filip Tehlar8df3de42023-01-27 13:14:34 +0100169 s.assertNil(runNginxPerf(s, "cps", "ab"))
170}
171
Adrian Villincee15aa2024-03-14 11:42:55 -0400172func NginxPerfRpsTest(s *NoTopoSuite) {
Filip Tehlar8df3de42023-01-27 13:14:34 +0100173 s.assertNil(runNginxPerf(s, "rps", "ab"))
174}
175
Adrian Villincee15aa2024-03-14 11:42:55 -0400176func NginxPerfWrkTest(s *NoTopoSuite) {
Filip Tehlar8df3de42023-01-27 13:14:34 +0100177 s.assertNil(runNginxPerf(s, "", "wrk"))
178}