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" |
| 7 | "strings" |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 8 | "time" |
| 9 | ) |
| 10 | |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 11 | func (s *NsSuite) TestHttpTps() { |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame^] | 12 | iface := s.netInterfaces[clientInterface] |
| 13 | client_ip := iface.Ip4AddressString() |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 14 | port := "8080" |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame^] | 15 | finished := make(chan error, 1) |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 16 | |
| 17 | container := s.getContainerByName("vpp") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 18 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame^] | 19 | // configure vpp in the container |
| 20 | container.vppInstance.vppctl("http tps uri tcp://0.0.0.0/8080") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 21 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame^] | 22 | go startWget(finished, client_ip, port, "test_file_10M", "client") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 23 | // wait for client |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame^] | 24 | err := <-finished |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 25 | s.assertNil(err) |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 26 | } |
| 27 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 28 | func (s *VethsSuite) TestHttpCli() { |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 29 | serverContainer := s.getContainerByName("server-vpp") |
| 30 | clientContainer := s.getContainerByName("client-vpp") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 31 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame^] | 32 | serverVeth := s.netInterfaces[serverInterfaceName] |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 33 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame^] | 34 | serverContainer.vppInstance.vppctl("http cli server") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 35 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame^] | 36 | uri := "http://" + serverVeth.Ip4AddressString() + "/80" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 37 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame^] | 38 | o := clientContainer.vppInstance.vppctl("http cli client" + |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 39 | " uri " + uri + " query /show/version") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 40 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 41 | s.log(o) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 42 | s.assertContains(o, "<html>", "<html> not found in the result!") |
Filip Tehlar | b15a000 | 2022-11-10 12:34:17 +0100 | [diff] [blame] | 43 | } |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 44 | |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 45 | func waitForApp(vppInst *VppInstance, appName string, timeout int) error { |
| 46 | for i := 0; i < timeout; i++ { |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame^] | 47 | o := vppInst.vppctl("show app") |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 48 | if strings.Contains(o, appName) { |
| 49 | return nil |
| 50 | } |
| 51 | time.Sleep(1 * time.Second) |
| 52 | } |
| 53 | return fmt.Errorf("Timeout while waiting for app '%s'", appName) |
| 54 | } |
| 55 | |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 56 | func (s *NoTopoSuite) TestNginx() { |
| 57 | query := "return_ok" |
| 58 | finished := make(chan error, 1) |
| 59 | vppCont := s.getContainerByName("vpp") |
| 60 | vppInst := NewVppInstance(vppCont) |
| 61 | vppInst.actionFuncName = "ConfigureTap" |
| 62 | s.assertNil(vppInst.start(), "failed to start vpp") |
| 63 | |
| 64 | nginxCont := s.getContainerByName("nginx") |
| 65 | s.assertNil(nginxCont.run()) |
| 66 | |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 67 | err := waitForApp(vppInst, "-app", 5) |
| 68 | s.assertNil(err) |
Filip Tehlar | c204c87 | 2022-12-21 08:59:16 +0100 | [diff] [blame] | 69 | |
| 70 | defer func() { os.Remove(query) }() |
| 71 | go startWget(finished, "10.10.10.1", "80", query, "") |
| 72 | s.assertNil(<-finished) |
| 73 | } |
Filip Tehlar | 8df3de4 | 2023-01-27 13:14:34 +0100 | [diff] [blame] | 74 | |
| 75 | func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string) error { |
| 76 | nRequests := 1000000 |
| 77 | nClients := 2000 |
| 78 | var args []string |
| 79 | var exeName string |
| 80 | |
| 81 | if ab_or_wrk == "ab" { |
| 82 | args = []string{"-n", fmt.Sprintf("%d", nRequests), "-c", |
| 83 | fmt.Sprintf("%d", nClients)} |
| 84 | if mode == "rps" { |
| 85 | args = append(args, "-k") |
| 86 | } else if mode != "cps" { |
| 87 | return fmt.Errorf("invalid mode %s; expected cps/rps", mode) |
| 88 | } |
| 89 | args = append(args, "http://10.10.10.1:80/64B.json") |
| 90 | exeName = "ab" |
| 91 | } else { |
| 92 | args = []string{"-c", fmt.Sprintf("%d", nClients), "-t", "2", "-d", "30", |
| 93 | "http://10.10.10.1:80"} |
| 94 | exeName = "wrk" |
| 95 | } |
| 96 | |
| 97 | vppCont := s.getContainerByName("vpp") |
| 98 | vppInst := NewVppInstance(vppCont) |
| 99 | vppInst.actionFuncName = "ConfigureTap" |
| 100 | s.assertNil(vppInst.start(), "failed to start vpp") |
| 101 | |
| 102 | nginxCont := s.getContainerByName("nginx") |
| 103 | s.assertNil(nginxCont.run()) |
| 104 | err := waitForApp(vppInst, "-app", 5) |
| 105 | s.assertNil(err) |
| 106 | |
| 107 | cmd := exec.Command(exeName, args...) |
| 108 | fmt.Println(cmd) |
| 109 | o, _ := cmd.CombinedOutput() |
| 110 | fmt.Print(string(o)) |
| 111 | return nil |
| 112 | } |
| 113 | |
| 114 | func (s *NoTopoSuite) TestNginxPerfCps() { |
| 115 | s.assertNil(runNginxPerf(s, "cps", "ab")) |
| 116 | } |
| 117 | |
| 118 | func (s *NoTopoSuite) TestNginxPerfRps() { |
| 119 | s.assertNil(runNginxPerf(s, "rps", "ab")) |
| 120 | } |
| 121 | |
| 122 | func (s *NoTopoSuite) TestNginxPerfWrk() { |
| 123 | s.assertNil(runNginxPerf(s, "", "wrk")) |
| 124 | } |