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() { |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 10 | iface := s.getInterfaceByName(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) |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 14 | clientNetns := s.getNetNamespaceByName("cln") |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 15 | |
| 16 | container := s.getContainerByName("vpp") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 17 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 18 | // configure vpp in the container |
| 19 | container.vppInstance.vppctl("http tps uri tcp://0.0.0.0/8080") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 20 | |
adrianvillin | fbf5f2b | 2024-02-13 03:26:25 -0500 | [diff] [blame] | 21 | go s.startWget(finished, client_ip, port, "test_file_10M", clientNetns) |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 22 | // wait for client |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 23 | err := <-finished |
adrianvillin | 7c67547 | 2024-02-12 02:44:53 -0500 | [diff] [blame] | 24 | s.assertNil(err, err) |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 25 | } |
| 26 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 27 | func (s *VethsSuite) TestHttpCli() { |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 28 | serverContainer := s.getContainerByName("server-vpp") |
| 29 | clientContainer := s.getContainerByName("client-vpp") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 30 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 31 | serverVeth := s.getInterfaceByName(serverInterfaceName) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 32 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 33 | serverContainer.vppInstance.vppctl("http cli server") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 34 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 35 | uri := "http://" + serverVeth.ip4AddressString() + "/80" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 36 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 37 | o := clientContainer.vppInstance.vppctl("http cli client" + |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 38 | " uri " + uri + " query /show/version") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 39 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 40 | s.log(o) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 41 | s.assertContains(o, "<html>", "<html> not found in the result!") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 42 | } |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 43 | |
Filip Tehlar | 31eaea9 | 2023-06-15 10:06:57 +0200 | [diff] [blame] | 44 | func (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) |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 53 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
Filip Tehlar | 31eaea9 | 2023-06-15 10:06:57 +0200 | [diff] [blame] | 54 | |
| 55 | defer func() { os.Remove(query) }() |
| 56 | curlCont := s.getContainerByName("curl") |
Filip Tehlar | 87241fe | 2024-01-17 21:45:28 +0100 | [diff] [blame] | 57 | 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] | 58 | curlCont.extraRunningArgs = args |
| 59 | o, err := curlCont.combinedOutput() |
adrianvillin | 7c67547 | 2024-02-12 02:44:53 -0500 | [diff] [blame] | 60 | s.assertNil(err, err) |
Filip Tehlar | 31eaea9 | 2023-06-15 10:06:57 +0200 | [diff] [blame] | 61 | s.assertContains(o, "<http>", "<http> not found in the result!") |
| 62 | } |
| 63 | |
Filip Tehlar | cc1475c | 2023-11-29 12:59:05 +0100 | [diff] [blame] | 64 | func (s *NoTopoSuite) TestHttpStaticProm() { |
| 65 | finished := make(chan error, 1) |
| 66 | query := "stats.prom" |
| 67 | vpp := s.getContainerByName("vpp").vppInstance |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 68 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
Filip Tehlar | cc1475c | 2023-11-29 12:59:05 +0100 | [diff] [blame] | 69 | 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 |
adrianvillin | 7c67547 | 2024-02-12 02:44:53 -0500 | [diff] [blame] | 73 | s.assertNil(err, err) |
Filip Tehlar | cc1475c | 2023-11-29 12:59:05 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Maros Ondrejicka | ad40607 | 2023-02-24 14:16:25 +0100 | [diff] [blame] | 76 | func (s *NoTopoSuite) TestNginxAsServer() { |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 77 | query := "return_ok" |
| 78 | finished := make(chan error, 1) |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 79 | |
| 80 | nginxCont := s.getContainerByName("nginx") |
| 81 | s.assertNil(nginxCont.run()) |
| 82 | |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 83 | vpp := s.getContainerByName("vpp").vppInstance |
Florin Coras | e2415f7 | 2023-02-28 14:51:03 -0800 | [diff] [blame] | 84 | vpp.waitForApp("nginx-", 5) |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 85 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 86 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 87 | |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 88 | defer func() { os.Remove(query) }() |
Filip Tehlar | 4b3598e | 2023-09-02 08:54:21 +0200 | [diff] [blame] | 89 | go s.startWget(finished, serverAddress, "80", query, "") |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 90 | s.assertNil(<-finished) |
| 91 | } |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 92 | |
Filip Tehlar | 5811356 | 2023-04-15 20:41:18 +0200 | [diff] [blame] | 93 | func 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 Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 103 | func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string) error { |
| 104 | nRequests := 1000000 |
Filip Tehlar | dda1f68 | 2023-04-24 17:52:50 +0200 | [diff] [blame] | 105 | nClients := 1000 |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 106 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 107 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 108 | |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 109 | vpp := s.getContainerByName("vpp").vppInstance |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 110 | |
adrianvillin | fbf5f2b | 2024-02-13 03:26:25 -0500 | [diff] [blame] | 111 | nginxCont := s.getContainerByName(singleTopoContainerNginx) |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 112 | s.assertNil(nginxCont.run()) |
Florin Coras | e2415f7 | 2023-02-28 14:51:03 -0800 | [diff] [blame] | 113 | vpp.waitForApp("nginx-", 5) |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 114 | |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 115 | 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 Tehlar | dda1f68 | 2023-04-24 17:52:50 +0200 | [diff] [blame] | 123 | // don't exit on socket receive errors |
| 124 | args += " -r" |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 125 | args += " http://" + serverAddress + ":80/64B.json" |
| 126 | abCont.extraRunningArgs = args |
| 127 | o, err := abCont.combinedOutput() |
Filip Tehlar | 5811356 | 2023-04-15 20:41:18 +0200 | [diff] [blame] | 128 | rps := parseString(o, "Requests per second:") |
| 129 | s.log(rps, err) |
adrianvillin | 7c67547 | 2024-02-12 02:44:53 -0500 | [diff] [blame] | 130 | s.assertNil(err, "err: '%s', output: '%s'", err, o) |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 131 | } 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 Tehlar | 5811356 | 2023-04-15 20:41:18 +0200 | [diff] [blame] | 137 | rps := parseString(o, "requests") |
| 138 | s.log(rps, err) |
adrianvillin | 7c67547 | 2024-02-12 02:44:53 -0500 | [diff] [blame] | 139 | s.assertNil(err, "err: '%s', output: '%s'", err, o) |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 140 | } |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 141 | return nil |
| 142 | } |
| 143 | |
| 144 | func (s *NoTopoSuite) TestNginxPerfCps() { |
| 145 | s.assertNil(runNginxPerf(s, "cps", "ab")) |
| 146 | } |
| 147 | |
| 148 | func (s *NoTopoSuite) TestNginxPerfRps() { |
| 149 | s.assertNil(runNginxPerf(s, "rps", "ab")) |
| 150 | } |
| 151 | |
| 152 | func (s *NoTopoSuite) TestNginxPerfWrk() { |
| 153 | s.assertNil(runNginxPerf(s, "", "wrk")) |
| 154 | } |