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 | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 6 | "os/exec" |
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 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 20 | go 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 | |
Maros Ondrejicka | ad40607 | 2023-02-24 14:16:25 +0100 | [diff] [blame] | 43 | func (s *NoTopoSuite) TestNginxAsServer() { |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 44 | query := "return_ok" |
| 45 | finished := make(chan error, 1) |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 46 | |
| 47 | nginxCont := s.getContainerByName("nginx") |
| 48 | s.assertNil(nginxCont.run()) |
| 49 | |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 50 | vpp := s.getContainerByName("vpp").vppInstance |
Florin Coras | e2415f7 | 2023-02-28 14:51:03 -0800 | [diff] [blame] | 51 | vpp.waitForApp("nginx-", 5) |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 52 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame^] | 53 | serverAddress := s.netInterfaces[tapInterfaceName].peer.ip4AddressString() |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 54 | |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 55 | defer func() { os.Remove(query) }() |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 56 | go startWget(finished, serverAddress, "80", query, "") |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 57 | s.assertNil(<-finished) |
| 58 | } |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 59 | |
| 60 | func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string) error { |
| 61 | nRequests := 1000000 |
| 62 | nClients := 2000 |
| 63 | var args []string |
| 64 | var exeName string |
| 65 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame^] | 66 | serverAddress := s.netInterfaces[tapInterfaceName].peer.ip4AddressString() |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 67 | |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 68 | if ab_or_wrk == "ab" { |
| 69 | args = []string{"-n", fmt.Sprintf("%d", nRequests), "-c", |
| 70 | fmt.Sprintf("%d", nClients)} |
| 71 | if mode == "rps" { |
| 72 | args = append(args, "-k") |
| 73 | } else if mode != "cps" { |
| 74 | return fmt.Errorf("invalid mode %s; expected cps/rps", mode) |
| 75 | } |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 76 | args = append(args, "http://"+serverAddress+":80/64B.json") |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 77 | exeName = "ab" |
| 78 | } else { |
| 79 | args = []string{"-c", fmt.Sprintf("%d", nClients), "-t", "2", "-d", "30", |
Maros Ondrejicka | ad40607 | 2023-02-24 14:16:25 +0100 | [diff] [blame] | 80 | "http://" + serverAddress + ":80/64B.json"} |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 81 | exeName = "wrk" |
| 82 | } |
| 83 | |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 84 | vpp := s.getContainerByName("vpp").vppInstance |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 85 | |
| 86 | nginxCont := s.getContainerByName("nginx") |
| 87 | s.assertNil(nginxCont.run()) |
Florin Coras | e2415f7 | 2023-02-28 14:51:03 -0800 | [diff] [blame] | 88 | vpp.waitForApp("nginx-", 5) |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 89 | |
| 90 | cmd := exec.Command(exeName, args...) |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 91 | s.log(cmd) |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 92 | o, _ := cmd.CombinedOutput() |
Maros Ondrejicka | 7550dd2 | 2023-02-07 20:40:27 +0100 | [diff] [blame] | 93 | s.log(string(o)) |
Maros Ondrejicka | 2ddb2fd | 2023-02-15 17:44:46 +0100 | [diff] [blame] | 94 | s.assertNotEmpty(o) |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 95 | return nil |
| 96 | } |
| 97 | |
| 98 | func (s *NoTopoSuite) TestNginxPerfCps() { |
| 99 | s.assertNil(runNginxPerf(s, "cps", "ab")) |
| 100 | } |
| 101 | |
| 102 | func (s *NoTopoSuite) TestNginxPerfRps() { |
| 103 | s.assertNil(runNginxPerf(s, "rps", "ab")) |
| 104 | } |
| 105 | |
| 106 | func (s *NoTopoSuite) TestNginxPerfWrk() { |
| 107 | s.assertNil(runNginxPerf(s, "", "wrk")) |
| 108 | } |