blob: 943c8a591d4d62388f035a31f4417ba5f4a5154d [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"
Filip Tehlarc204c872022-12-21 08:59:16 +01007)
8
Filip Tehlarb15a0002022-11-10 12:34:17 +01009func (s *NsSuite) TestHttpTps() {
adrianvillin28bd8f02024-02-13 06:00:02 -050010 iface := s.getInterfaceByName(clientInterface)
Maros Ondrejickae7625d02023-02-28 16:55:01 +010011 client_ip := iface.ip4AddressString()
Filip Tehlarb15a0002022-11-10 12:34:17 +010012 port := "8080"
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010013 finished := make(chan error, 1)
adrianvillin28bd8f02024-02-13 06:00:02 -050014 clientNetns := s.getNetNamespaceByName("cln")
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010015
16 container := s.getContainerByName("vpp")
Filip Tehlarb15a0002022-11-10 12:34:17 +010017
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010018 // configure vpp in the container
19 container.vppInstance.vppctl("http tps uri tcp://0.0.0.0/8080")
Filip Tehlarb15a0002022-11-10 12:34:17 +010020
adrianvillinfbf5f2b2024-02-13 03:26:25 -050021 go s.startWget(finished, client_ip, port, "test_file_10M", clientNetns)
Filip Tehlarb15a0002022-11-10 12:34:17 +010022 // wait for client
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010023 err := <-finished
adrianvillin7c675472024-02-12 02:44:53 -050024 s.assertNil(err, err)
Filip Tehlarb15a0002022-11-10 12:34:17 +010025}
26
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010027func (s *VethsSuite) TestHttpCli() {
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010028 serverContainer := s.getContainerByName("server-vpp")
29 clientContainer := s.getContainerByName("client-vpp")
Filip Tehlarb15a0002022-11-10 12:34:17 +010030
adrianvillin28bd8f02024-02-13 06:00:02 -050031 serverVeth := s.getInterfaceByName(serverInterfaceName)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010032
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010033 serverContainer.vppInstance.vppctl("http cli server")
Filip Tehlarb15a0002022-11-10 12:34:17 +010034
Maros Ondrejickae7625d02023-02-28 16:55:01 +010035 uri := "http://" + serverVeth.ip4AddressString() + "/80"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010036
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010037 o := clientContainer.vppInstance.vppctl("http cli client" +
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010038 " uri " + uri + " query /show/version")
Filip Tehlarb15a0002022-11-10 12:34:17 +010039
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010040 s.log(o)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010041 s.assertContains(o, "<html>", "<html> not found in the result!")
Filip Tehlarb15a0002022-11-10 12:34:17 +010042}
Filip Tehlarc204c872022-12-21 08:59:16 +010043
Filip Tehlar31eaea92023-06-15 10:06:57 +020044func (s *NoTopoSuite) TestNginxHttp3() {
45 s.SkipUnlessExtendedTestsBuilt()
46
47 query := "index.html"
48 nginxCont := s.getContainerByName("nginx-http3")
49 s.assertNil(nginxCont.run())
50
51 vpp := s.getContainerByName("vpp").vppInstance
52 vpp.waitForApp("nginx-", 5)
adrianvillin28bd8f02024-02-13 06:00:02 -050053 serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString()
Filip Tehlar31eaea92023-06-15 10:06:57 +020054
55 defer func() { os.Remove(query) }()
56 curlCont := s.getContainerByName("curl")
Filip Tehlar87241fe2024-01-17 21:45:28 +010057 args := fmt.Sprintf("curl --noproxy '*' --local-port 55444 --http3-only -k https://%s:8443/%s", serverAddress, query)
Filip Tehlar31eaea92023-06-15 10:06:57 +020058 curlCont.extraRunningArgs = args
59 o, err := curlCont.combinedOutput()
adrianvillin7c675472024-02-12 02:44:53 -050060 s.assertNil(err, err)
Filip Tehlar31eaea92023-06-15 10:06:57 +020061 s.assertContains(o, "<http>", "<http> not found in the result!")
62}
63
Filip Tehlarcc1475c2023-11-29 12:59:05 +010064func (s *NoTopoSuite) TestHttpStaticProm() {
65 finished := make(chan error, 1)
66 query := "stats.prom"
67 vpp := s.getContainerByName("vpp").vppInstance
adrianvillin28bd8f02024-02-13 06:00:02 -050068 serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString()
Filip Tehlarcc1475c2023-11-29 12:59:05 +010069 s.log(vpp.vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers"))
70 s.log(vpp.vppctl("prom enable"))
71 go s.startWget(finished, serverAddress, "80", query, "")
72 err := <-finished
adrianvillin7c675472024-02-12 02:44:53 -050073 s.assertNil(err, err)
Filip Tehlarcc1475c2023-11-29 12:59:05 +010074}
75
Maros Ondrejickaad406072023-02-24 14:16:25 +010076func (s *NoTopoSuite) TestNginxAsServer() {
Filip Tehlarc204c872022-12-21 08:59:16 +010077 query := "return_ok"
78 finished := make(chan error, 1)
Filip Tehlarc204c872022-12-21 08:59:16 +010079
80 nginxCont := s.getContainerByName("nginx")
81 s.assertNil(nginxCont.run())
82
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010083 vpp := s.getContainerByName("vpp").vppInstance
Florin Corase2415f72023-02-28 14:51:03 -080084 vpp.waitForApp("nginx-", 5)
Filip Tehlarc204c872022-12-21 08:59:16 +010085
adrianvillin28bd8f02024-02-13 06:00:02 -050086 serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010087
Filip Tehlarc204c872022-12-21 08:59:16 +010088 defer func() { os.Remove(query) }()
Filip Tehlar4b3598e2023-09-02 08:54:21 +020089 go s.startWget(finished, serverAddress, "80", query, "")
Filip Tehlarc204c872022-12-21 08:59:16 +010090 s.assertNil(<-finished)
91}
Filip Tehlar8df3de42023-01-27 13:14:34 +010092
Filip Tehlar58113562023-04-15 20:41:18 +020093func parseString(s, pattern string) string {
94 temp := strings.Split(s, "\n")
95 for _, item := range temp {
96 if strings.Contains(item, pattern) {
97 return item
98 }
99 }
100 return ""
101}
102
Filip Tehlar8df3de42023-01-27 13:14:34 +0100103func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string) error {
104 nRequests := 1000000
Filip Tehlardda1f682023-04-24 17:52:50 +0200105 nClients := 1000
Filip Tehlar8df3de42023-01-27 13:14:34 +0100106
adrianvillin28bd8f02024-02-13 06:00:02 -0500107 serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100108
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100109 vpp := s.getContainerByName("vpp").vppInstance
Filip Tehlar8df3de42023-01-27 13:14:34 +0100110
adrianvillinfbf5f2b2024-02-13 03:26:25 -0500111 nginxCont := s.getContainerByName(singleTopoContainerNginx)
Filip Tehlar8df3de42023-01-27 13:14:34 +0100112 s.assertNil(nginxCont.run())
Florin Corase2415f72023-02-28 14:51:03 -0800113 vpp.waitForApp("nginx-", 5)
Filip Tehlar8df3de42023-01-27 13:14:34 +0100114
Filip Tehlarb41b0af2023-03-20 12:39:20 +0100115 if ab_or_wrk == "ab" {
116 abCont := s.getContainerByName("ab")
117 args := fmt.Sprintf("-n %d -c %d", nRequests, nClients)
118 if mode == "rps" {
119 args += " -k"
120 } else if mode != "cps" {
121 return fmt.Errorf("invalid mode %s; expected cps/rps", mode)
122 }
Filip Tehlardda1f682023-04-24 17:52:50 +0200123 // don't exit on socket receive errors
124 args += " -r"
Filip Tehlarb41b0af2023-03-20 12:39:20 +0100125 args += " http://" + serverAddress + ":80/64B.json"
126 abCont.extraRunningArgs = args
127 o, err := abCont.combinedOutput()
Filip Tehlar58113562023-04-15 20:41:18 +0200128 rps := parseString(o, "Requests per second:")
129 s.log(rps, err)
adrianvillin7c675472024-02-12 02:44:53 -0500130 s.assertNil(err, "err: '%s', output: '%s'", err, o)
Filip Tehlarb41b0af2023-03-20 12:39:20 +0100131 } else {
132 wrkCont := s.getContainerByName("wrk")
133 args := fmt.Sprintf("-c %d -t 2 -d 30 http://%s:80/64B.json", nClients,
134 serverAddress)
135 wrkCont.extraRunningArgs = args
136 o, err := wrkCont.combinedOutput()
Filip Tehlar58113562023-04-15 20:41:18 +0200137 rps := parseString(o, "requests")
138 s.log(rps, err)
adrianvillin7c675472024-02-12 02:44:53 -0500139 s.assertNil(err, "err: '%s', output: '%s'", err, o)
Filip Tehlarb41b0af2023-03-20 12:39:20 +0100140 }
Filip Tehlar8df3de42023-01-27 13:14:34 +0100141 return nil
142}
143
144func (s *NoTopoSuite) TestNginxPerfCps() {
145 s.assertNil(runNginxPerf(s, "cps", "ab"))
146}
147
148func (s *NoTopoSuite) TestNginxPerfRps() {
149 s.assertNil(runNginxPerf(s, "rps", "ab"))
150}
151
152func (s *NoTopoSuite) TestNginxPerfWrk() {
153 s.assertNil(runNginxPerf(s, "", "wrk"))
154}