Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 1 | package main |
| 2 | |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 3 | import ( |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 4 | "fmt" |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 5 | "os" |
Filip Tehlar | 5811356 | 2023-04-15 20:41:18 +0200 | [diff] [blame] | 6 | "strings" |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 7 | ) |
| 8 | |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 9 | func (s *NsSuite) TestHttpTps() { |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 10 | iface := s.netInterfaces[clientInterface] |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 11 | client_ip := iface.ip4AddressString() |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 12 | port := "8080" |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 13 | finished := make(chan error, 1) |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 14 | |
| 15 | container := s.getContainerByName("vpp") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 16 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 17 | // configure vpp in the container |
| 18 | container.vppInstance.vppctl("http tps uri tcp://0.0.0.0/8080") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 19 | |
Filip Tehlar | 4b3598e | 2023-09-02 08:54:21 +0200 | [diff] [blame] | 20 | go s.startWget(finished, client_ip, port, "test_file_10M", "client") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 21 | // wait for client |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 22 | err := <-finished |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 23 | s.assertNil(err) |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 24 | } |
| 25 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 26 | func (s *VethsSuite) TestHttpCli() { |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 27 | serverContainer := s.getContainerByName("server-vpp") |
| 28 | clientContainer := s.getContainerByName("client-vpp") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 29 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 30 | serverVeth := s.netInterfaces[serverInterfaceName] |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 31 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 32 | serverContainer.vppInstance.vppctl("http cli server") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 33 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 34 | uri := "http://" + serverVeth.ip4AddressString() + "/80" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 35 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 36 | o := clientContainer.vppInstance.vppctl("http cli client" + |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 37 | " uri " + uri + " query /show/version") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 38 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 39 | s.log(o) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 40 | s.assertContains(o, "<html>", "<html> not found in the result!") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 41 | } |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 42 | |
Filip Tehlar | 31eaea9 | 2023-06-15 10:06:57 +0200 | [diff] [blame] | 43 | func (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") |
Filip Tehlar | 87241fe | 2024-01-17 21:45:28 +0100 | [diff] [blame] | 56 | args := fmt.Sprintf("curl --noproxy '*' --local-port 55444 --http3-only -k https://%s:8443/%s", serverAddress, query) |
Filip Tehlar | 31eaea9 | 2023-06-15 10:06:57 +0200 | [diff] [blame] | 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 | |
Filip Tehlar | cc1475c | 2023-11-29 12:59:05 +0100 | [diff] [blame] | 63 | func (s *NoTopoSuite) TestHttpStaticProm() { |
| 64 | finished := make(chan error, 1) |
| 65 | query := "stats.prom" |
| 66 | vpp := s.getContainerByName("vpp").vppInstance |
| 67 | serverAddress := s.netInterfaces[tapInterfaceName].peer.ip4AddressString() |
| 68 | s.log(vpp.vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers")) |
| 69 | s.log(vpp.vppctl("prom enable")) |
| 70 | go s.startWget(finished, serverAddress, "80", query, "") |
| 71 | err := <-finished |
| 72 | s.assertNil(err) |
| 73 | } |
| 74 | |
Maros Ondrejicka | ad40607 | 2023-02-24 14:16:25 +0100 | [diff] [blame] | 75 | func (s *NoTopoSuite) TestNginxAsServer() { |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 76 | query := "return_ok" |
| 77 | finished := make(chan error, 1) |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 78 | |
| 79 | nginxCont := s.getContainerByName("nginx") |
| 80 | s.assertNil(nginxCont.run()) |
| 81 | |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 82 | vpp := s.getContainerByName("vpp").vppInstance |
Florin Coras | e2415f7 | 2023-02-28 14:51:03 -0800 | [diff] [blame] | 83 | vpp.waitForApp("nginx-", 5) |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 84 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 85 | serverAddress := s.netInterfaces[tapInterfaceName].peer.ip4AddressString() |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 86 | |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 87 | defer func() { os.Remove(query) }() |
Filip Tehlar | 4b3598e | 2023-09-02 08:54:21 +0200 | [diff] [blame] | 88 | go s.startWget(finished, serverAddress, "80", query, "") |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 89 | s.assertNil(<-finished) |
| 90 | } |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 91 | |
Filip Tehlar | 5811356 | 2023-04-15 20:41:18 +0200 | [diff] [blame] | 92 | func parseString(s, pattern string) string { |
| 93 | temp := strings.Split(s, "\n") |
| 94 | for _, item := range temp { |
| 95 | if strings.Contains(item, pattern) { |
| 96 | return item |
| 97 | } |
| 98 | } |
| 99 | return "" |
| 100 | } |
| 101 | |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 102 | func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string) error { |
| 103 | nRequests := 1000000 |
Filip Tehlar | dda1f68 | 2023-04-24 17:52:50 +0200 | [diff] [blame] | 104 | nClients := 1000 |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 105 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 106 | serverAddress := s.netInterfaces[tapInterfaceName].peer.ip4AddressString() |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 107 | |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 108 | vpp := s.getContainerByName("vpp").vppInstance |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 109 | |
| 110 | nginxCont := s.getContainerByName("nginx") |
| 111 | s.assertNil(nginxCont.run()) |
Florin Coras | e2415f7 | 2023-02-28 14:51:03 -0800 | [diff] [blame] | 112 | vpp.waitForApp("nginx-", 5) |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 113 | |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 114 | if ab_or_wrk == "ab" { |
| 115 | abCont := s.getContainerByName("ab") |
| 116 | args := fmt.Sprintf("-n %d -c %d", nRequests, nClients) |
| 117 | if mode == "rps" { |
| 118 | args += " -k" |
| 119 | } else if mode != "cps" { |
| 120 | return fmt.Errorf("invalid mode %s; expected cps/rps", mode) |
| 121 | } |
Filip Tehlar | dda1f68 | 2023-04-24 17:52:50 +0200 | [diff] [blame] | 122 | // don't exit on socket receive errors |
| 123 | args += " -r" |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 124 | args += " http://" + serverAddress + ":80/64B.json" |
| 125 | abCont.extraRunningArgs = args |
| 126 | o, err := abCont.combinedOutput() |
Filip Tehlar | 5811356 | 2023-04-15 20:41:18 +0200 | [diff] [blame] | 127 | rps := parseString(o, "Requests per second:") |
| 128 | s.log(rps, err) |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 129 | s.assertNil(err) |
| 130 | } else { |
| 131 | wrkCont := s.getContainerByName("wrk") |
| 132 | args := fmt.Sprintf("-c %d -t 2 -d 30 http://%s:80/64B.json", nClients, |
| 133 | serverAddress) |
| 134 | wrkCont.extraRunningArgs = args |
| 135 | o, err := wrkCont.combinedOutput() |
Filip Tehlar | 5811356 | 2023-04-15 20:41:18 +0200 | [diff] [blame] | 136 | rps := parseString(o, "requests") |
| 137 | s.log(rps, err) |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 138 | s.assertNil(err) |
| 139 | } |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 140 | return nil |
| 141 | } |
| 142 | |
| 143 | func (s *NoTopoSuite) TestNginxPerfCps() { |
| 144 | s.assertNil(runNginxPerf(s, "cps", "ab")) |
| 145 | } |
| 146 | |
| 147 | func (s *NoTopoSuite) TestNginxPerfRps() { |
| 148 | s.assertNil(runNginxPerf(s, "rps", "ab")) |
| 149 | } |
| 150 | |
| 151 | func (s *NoTopoSuite) TestNginxPerfWrk() { |
| 152 | s.assertNil(runNginxPerf(s, "", "wrk")) |
| 153 | } |