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