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" |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 7 | "time" |
| 8 | |
| 9 | . "github.com/onsi/ginkgo/v2" |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 10 | ) |
| 11 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 12 | func init() { |
| 13 | registerNsTests(HttpTpsTest) |
| 14 | registerVethTests(HttpCliTest) |
| 15 | registerNoTopoTests(NginxHttp3Test, NginxAsServerTest, |
| 16 | NginxPerfCpsTest, NginxPerfRpsTest, NginxPerfWrkTest) |
| 17 | registerNoTopoSoloTests(HttpStaticPromTest) |
| 18 | } |
| 19 | |
| 20 | func HttpTpsTest(s *NsSuite) { |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 21 | iface := s.getInterfaceByName(clientInterface) |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 22 | client_ip := iface.ip4AddressString() |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 23 | port := "8080" |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 24 | finished := make(chan error, 1) |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 25 | clientNetns := s.getNetNamespaceByName("cln") |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 26 | |
| 27 | container := s.getContainerByName("vpp") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 28 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 29 | // configure vpp in the container |
| 30 | container.vppInstance.vppctl("http tps uri tcp://0.0.0.0/8080") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 31 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 32 | go func() { |
| 33 | defer GinkgoRecover() |
| 34 | s.startWget(finished, client_ip, port, "test_file_10M", clientNetns) |
| 35 | }() |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 36 | // wait for client |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 37 | err := <-finished |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 38 | s.assertNil(err, fmt.Sprint(err)) |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 39 | } |
| 40 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 41 | func HttpCliTest(s *VethsSuite) { |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 42 | serverContainer := s.getContainerByName("server-vpp") |
| 43 | clientContainer := s.getContainerByName("client-vpp") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 44 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 45 | serverVeth := s.getInterfaceByName(serverInterfaceName) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 46 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 47 | serverContainer.vppInstance.vppctl("http cli server") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 48 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 49 | uri := "http://" + serverVeth.ip4AddressString() + "/80" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 50 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 51 | o := clientContainer.vppInstance.vppctl("http cli client" + |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 52 | " uri " + uri + " query /show/version") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 53 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 54 | s.log(o) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 55 | s.assertContains(o, "<html>", "<html> not found in the result!") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 56 | } |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 57 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 58 | func NginxHttp3Test(s *NoTopoSuite) { |
Filip Tehlar | 31eaea9 | 2023-06-15 10:06:57 +0200 | [diff] [blame] | 59 | 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) |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 67 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
Filip Tehlar | 31eaea9 | 2023-06-15 10:06:57 +0200 | [diff] [blame] | 68 | |
| 69 | defer func() { os.Remove(query) }() |
| 70 | curlCont := s.getContainerByName("curl") |
Filip Tehlar | 87241fe | 2024-01-17 21:45:28 +0100 | [diff] [blame] | 71 | 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] | 72 | curlCont.extraRunningArgs = args |
| 73 | o, err := curlCont.combinedOutput() |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 74 | s.assertNil(err, fmt.Sprint(err)) |
Filip Tehlar | 31eaea9 | 2023-06-15 10:06:57 +0200 | [diff] [blame] | 75 | s.assertContains(o, "<http>", "<http> not found in the result!") |
| 76 | } |
| 77 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 78 | func HttpStaticPromTest(s *NoTopoSuite) { |
Filip Tehlar | cc1475c | 2023-11-29 12:59:05 +0100 | [diff] [blame] | 79 | finished := make(chan error, 1) |
| 80 | query := "stats.prom" |
| 81 | vpp := s.getContainerByName("vpp").vppInstance |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 82 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
Filip Tehlar | cc1475c | 2023-11-29 12:59:05 +0100 | [diff] [blame] | 83 | s.log(vpp.vppctl("http static server uri tcp://" + serverAddress + "/80 url-handlers")) |
| 84 | s.log(vpp.vppctl("prom enable")) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 85 | time.Sleep(time.Second * 5) |
| 86 | go func() { |
| 87 | defer GinkgoRecover() |
| 88 | s.startWget(finished, serverAddress, "80", query, "") |
| 89 | }() |
Filip Tehlar | cc1475c | 2023-11-29 12:59:05 +0100 | [diff] [blame] | 90 | err := <-finished |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 91 | s.assertNil(err) |
Filip Tehlar | cc1475c | 2023-11-29 12:59:05 +0100 | [diff] [blame] | 92 | } |
| 93 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 94 | func NginxAsServerTest(s *NoTopoSuite) { |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 95 | query := "return_ok" |
| 96 | finished := make(chan error, 1) |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 97 | |
| 98 | nginxCont := s.getContainerByName("nginx") |
| 99 | s.assertNil(nginxCont.run()) |
| 100 | |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 101 | vpp := s.getContainerByName("vpp").vppInstance |
Florin Coras | e2415f7 | 2023-02-28 14:51:03 -0800 | [diff] [blame] | 102 | vpp.waitForApp("nginx-", 5) |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 103 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 104 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 105 | |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 106 | defer func() { os.Remove(query) }() |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 107 | go func() { |
| 108 | defer GinkgoRecover() |
| 109 | s.startWget(finished, serverAddress, "80", query, "") |
| 110 | }() |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 111 | s.assertNil(<-finished) |
| 112 | } |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 113 | |
Filip Tehlar | 5811356 | 2023-04-15 20:41:18 +0200 | [diff] [blame] | 114 | func 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 Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 124 | func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string) error { |
| 125 | nRequests := 1000000 |
Filip Tehlar | dda1f68 | 2023-04-24 17:52:50 +0200 | [diff] [blame] | 126 | nClients := 1000 |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 127 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 128 | serverAddress := s.getInterfaceByName(tapInterfaceName).peer.ip4AddressString() |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 129 | |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 130 | vpp := s.getContainerByName("vpp").vppInstance |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 131 | |
adrianvillin | fbf5f2b | 2024-02-13 03:26:25 -0500 | [diff] [blame] | 132 | nginxCont := s.getContainerByName(singleTopoContainerNginx) |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 133 | s.assertNil(nginxCont.run()) |
Florin Coras | e2415f7 | 2023-02-28 14:51:03 -0800 | [diff] [blame] | 134 | vpp.waitForApp("nginx-", 5) |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 135 | |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 136 | 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 Tehlar | dda1f68 | 2023-04-24 17:52:50 +0200 | [diff] [blame] | 144 | // don't exit on socket receive errors |
| 145 | args += " -r" |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 146 | args += " http://" + serverAddress + ":80/64B.json" |
| 147 | abCont.extraRunningArgs = args |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 148 | time.Sleep(time.Second * 10) |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 149 | o, err := abCont.combinedOutput() |
Filip Tehlar | 5811356 | 2023-04-15 20:41:18 +0200 | [diff] [blame] | 150 | rps := parseString(o, "Requests per second:") |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 151 | s.log(rps) |
| 152 | s.log(err) |
adrianvillin | 7c67547 | 2024-02-12 02:44:53 -0500 | [diff] [blame] | 153 | s.assertNil(err, "err: '%s', output: '%s'", err, o) |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 154 | } 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 Tehlar | 5811356 | 2023-04-15 20:41:18 +0200 | [diff] [blame] | 160 | rps := parseString(o, "requests") |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 161 | s.log(rps) |
| 162 | s.log(err) |
adrianvillin | 7c67547 | 2024-02-12 02:44:53 -0500 | [diff] [blame] | 163 | s.assertNil(err, "err: '%s', output: '%s'", err, o) |
Filip Tehlar | b41b0af | 2023-03-20 12:39:20 +0100 | [diff] [blame] | 164 | } |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 165 | return nil |
| 166 | } |
| 167 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 168 | func NginxPerfCpsTest(s *NoTopoSuite) { |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 169 | s.assertNil(runNginxPerf(s, "cps", "ab")) |
| 170 | } |
| 171 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 172 | func NginxPerfRpsTest(s *NoTopoSuite) { |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 173 | s.assertNil(runNginxPerf(s, "rps", "ab")) |
| 174 | } |
| 175 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 176 | func NginxPerfWrkTest(s *NoTopoSuite) { |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 177 | s.assertNil(runNginxPerf(s, "", "wrk")) |
| 178 | } |