blob: 503f42a47c7d26d3f10230483acbbe9929fa3fe1 [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() {
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010010 iface := s.netInterfaces[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)
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010014
15 container := s.getContainerByName("vpp")
Filip Tehlarb15a0002022-11-10 12:34:17 +010016
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010017 // configure vpp in the container
18 container.vppInstance.vppctl("http tps uri tcp://0.0.0.0/8080")
Filip Tehlarb15a0002022-11-10 12:34:17 +010019
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010020 go startWget(finished, client_ip, port, "test_file_10M", "client")
Filip Tehlarb15a0002022-11-10 12:34:17 +010021 // wait for client
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010022 err := <-finished
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010023 s.assertNil(err)
Filip Tehlarb15a0002022-11-10 12:34:17 +010024}
25
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010026func (s *VethsSuite) TestHttpCli() {
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010027 serverContainer := s.getContainerByName("server-vpp")
28 clientContainer := s.getContainerByName("client-vpp")
Filip Tehlarb15a0002022-11-10 12:34:17 +010029
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010030 serverVeth := s.netInterfaces[serverInterfaceName]
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010031
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010032 serverContainer.vppInstance.vppctl("http cli server")
Filip Tehlarb15a0002022-11-10 12:34:17 +010033
Maros Ondrejickae7625d02023-02-28 16:55:01 +010034 uri := "http://" + serverVeth.ip4AddressString() + "/80"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010035
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010036 o := clientContainer.vppInstance.vppctl("http cli client" +
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010037 " uri " + uri + " query /show/version")
Filip Tehlarb15a0002022-11-10 12:34:17 +010038
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010039 s.log(o)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010040 s.assertContains(o, "<html>", "<html> not found in the result!")
Filip Tehlarb15a0002022-11-10 12:34:17 +010041}
Filip Tehlarc204c872022-12-21 08:59:16 +010042
Filip Tehlar31eaea92023-06-15 10:06:57 +020043func (s *NoTopoSuite) TestNginxHttp3() {
44 s.SkipUnlessExtendedTestsBuilt()
45
46 query := "index.html"
47 nginxCont := s.getContainerByName("nginx-http3")
48 s.assertNil(nginxCont.run())
49
50 vpp := s.getContainerByName("vpp").vppInstance
51 vpp.waitForApp("nginx-", 5)
52 serverAddress := s.netInterfaces[tapInterfaceName].peer.ip4AddressString()
53
54 defer func() { os.Remove(query) }()
55 curlCont := s.getContainerByName("curl")
56 args := fmt.Sprintf("curl --noproxy '*' --http3-only -k https://%s:8443/%s", serverAddress, query)
57 curlCont.extraRunningArgs = args
58 o, err := curlCont.combinedOutput()
59 s.assertNil(err)
60 s.assertContains(o, "<http>", "<http> not found in the result!")
61}
62
Maros Ondrejickaad406072023-02-24 14:16:25 +010063func (s *NoTopoSuite) TestNginxAsServer() {
Filip Tehlarc204c872022-12-21 08:59:16 +010064 query := "return_ok"
65 finished := make(chan error, 1)
Filip Tehlarc204c872022-12-21 08:59:16 +010066
67 nginxCont := s.getContainerByName("nginx")
68 s.assertNil(nginxCont.run())
69
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010070 vpp := s.getContainerByName("vpp").vppInstance
Florin Corase2415f72023-02-28 14:51:03 -080071 vpp.waitForApp("nginx-", 5)
Filip Tehlarc204c872022-12-21 08:59:16 +010072
Maros Ondrejickae7625d02023-02-28 16:55:01 +010073 serverAddress := s.netInterfaces[tapInterfaceName].peer.ip4AddressString()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010074
Filip Tehlarc204c872022-12-21 08:59:16 +010075 defer func() { os.Remove(query) }()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010076 go startWget(finished, serverAddress, "80", query, "")
Filip Tehlarc204c872022-12-21 08:59:16 +010077 s.assertNil(<-finished)
78}
Filip Tehlar8df3de42023-01-27 13:14:34 +010079
Filip Tehlar58113562023-04-15 20:41:18 +020080func parseString(s, pattern string) string {
81 temp := strings.Split(s, "\n")
82 for _, item := range temp {
83 if strings.Contains(item, pattern) {
84 return item
85 }
86 }
87 return ""
88}
89
Filip Tehlar8df3de42023-01-27 13:14:34 +010090func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string) error {
91 nRequests := 1000000
Filip Tehlardda1f682023-04-24 17:52:50 +020092 nClients := 1000
Filip Tehlar8df3de42023-01-27 13:14:34 +010093
Maros Ondrejickae7625d02023-02-28 16:55:01 +010094 serverAddress := s.netInterfaces[tapInterfaceName].peer.ip4AddressString()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010095
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010096 vpp := s.getContainerByName("vpp").vppInstance
Filip Tehlar8df3de42023-01-27 13:14:34 +010097
98 nginxCont := s.getContainerByName("nginx")
99 s.assertNil(nginxCont.run())
Florin Corase2415f72023-02-28 14:51:03 -0800100 vpp.waitForApp("nginx-", 5)
Filip Tehlar8df3de42023-01-27 13:14:34 +0100101
Filip Tehlarb41b0af2023-03-20 12:39:20 +0100102 if ab_or_wrk == "ab" {
103 abCont := s.getContainerByName("ab")
104 args := fmt.Sprintf("-n %d -c %d", nRequests, nClients)
105 if mode == "rps" {
106 args += " -k"
107 } else if mode != "cps" {
108 return fmt.Errorf("invalid mode %s; expected cps/rps", mode)
109 }
Filip Tehlardda1f682023-04-24 17:52:50 +0200110 // don't exit on socket receive errors
111 args += " -r"
Filip Tehlarb41b0af2023-03-20 12:39:20 +0100112 args += " http://" + serverAddress + ":80/64B.json"
113 abCont.extraRunningArgs = args
114 o, err := abCont.combinedOutput()
Filip Tehlar58113562023-04-15 20:41:18 +0200115 rps := parseString(o, "Requests per second:")
116 s.log(rps, err)
Filip Tehlarb41b0af2023-03-20 12:39:20 +0100117 s.assertNil(err)
118 } else {
119 wrkCont := s.getContainerByName("wrk")
120 args := fmt.Sprintf("-c %d -t 2 -d 30 http://%s:80/64B.json", nClients,
121 serverAddress)
122 wrkCont.extraRunningArgs = args
123 o, err := wrkCont.combinedOutput()
Filip Tehlar58113562023-04-15 20:41:18 +0200124 rps := parseString(o, "requests")
125 s.log(rps, err)
Filip Tehlarb41b0af2023-03-20 12:39:20 +0100126 s.assertNil(err)
127 }
Filip Tehlar8df3de42023-01-27 13:14:34 +0100128 return nil
129}
130
131func (s *NoTopoSuite) TestNginxPerfCps() {
132 s.assertNil(runNginxPerf(s, "cps", "ab"))
133}
134
135func (s *NoTopoSuite) TestNginxPerfRps() {
136 s.assertNil(runNginxPerf(s, "rps", "ab"))
137}
138
139func (s *NoTopoSuite) TestNginxPerfWrk() {
140 s.assertNil(runNginxPerf(s, "", "wrk"))
141}