blob: 912c98283b152b29aab7e1464a920c561616f556 [file] [log] [blame]
Filip Tehlarb15a0002022-11-10 12:34:17 +01001package main
2
Filip Tehlarc204c872022-12-21 08:59:16 +01003import (
Filip Tehlar8df3de42023-01-27 13:14:34 +01004 "fmt"
Filip Tehlarc204c872022-12-21 08:59:16 +01005 "os"
Filip Tehlar8df3de42023-01-27 13:14:34 +01006 "os/exec"
7 "strings"
Filip Tehlarc204c872022-12-21 08:59:16 +01008 "time"
9)
10
Filip Tehlarb15a0002022-11-10 12:34:17 +010011func (s *NsSuite) TestHttpTps() {
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010012 iface := s.netInterfaces[clientInterface]
13 client_ip := iface.Ip4AddressString()
Filip Tehlarb15a0002022-11-10 12:34:17 +010014 port := "8080"
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010015 finished := make(chan error, 1)
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010016
17 container := s.getContainerByName("vpp")
Filip Tehlarb15a0002022-11-10 12:34:17 +010018
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010019 // configure vpp in the container
20 container.vppInstance.vppctl("http tps uri tcp://0.0.0.0/8080")
Filip Tehlarb15a0002022-11-10 12:34:17 +010021
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010022 go startWget(finished, client_ip, port, "test_file_10M", "client")
Filip Tehlarb15a0002022-11-10 12:34:17 +010023 // wait for client
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010024 err := <-finished
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010025 s.assertNil(err)
Filip Tehlarb15a0002022-11-10 12:34:17 +010026}
27
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010028func (s *VethsSuite) TestHttpCli() {
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010029 serverContainer := s.getContainerByName("server-vpp")
30 clientContainer := s.getContainerByName("client-vpp")
Filip Tehlarb15a0002022-11-10 12:34:17 +010031
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010032 serverVeth := s.netInterfaces[serverInterfaceName]
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010033
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010034 serverContainer.vppInstance.vppctl("http cli server")
Filip Tehlarb15a0002022-11-10 12:34:17 +010035
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010036 uri := "http://" + serverVeth.Ip4AddressString() + "/80"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010037
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010038 o := clientContainer.vppInstance.vppctl("http cli client" +
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010039 " uri " + uri + " query /show/version")
Filip Tehlarb15a0002022-11-10 12:34:17 +010040
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010041 s.log(o)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010042 s.assertContains(o, "<html>", "<html> not found in the result!")
Filip Tehlarb15a0002022-11-10 12:34:17 +010043}
Filip Tehlarc204c872022-12-21 08:59:16 +010044
Filip Tehlar8df3de42023-01-27 13:14:34 +010045func waitForApp(vppInst *VppInstance, appName string, timeout int) error {
46 for i := 0; i < timeout; i++ {
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010047 o := vppInst.vppctl("show app")
Filip Tehlar8df3de42023-01-27 13:14:34 +010048 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 Tehlarc204c872022-12-21 08:59:16 +010056func (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 Tehlar8df3de42023-01-27 13:14:34 +010067 err := waitForApp(vppInst, "-app", 5)
68 s.assertNil(err)
Filip Tehlarc204c872022-12-21 08:59:16 +010069
70 defer func() { os.Remove(query) }()
71 go startWget(finished, "10.10.10.1", "80", query, "")
72 s.assertNil(<-finished)
73}
Filip Tehlar8df3de42023-01-27 13:14:34 +010074
75func 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
114func (s *NoTopoSuite) TestNginxPerfCps() {
115 s.assertNil(runNginxPerf(s, "cps", "ab"))
116}
117
118func (s *NoTopoSuite) TestNginxPerfRps() {
119 s.assertNil(runNginxPerf(s, "rps", "ab"))
120}
121
122func (s *NoTopoSuite) TestNginxPerfWrk() {
123 s.assertNil(runNginxPerf(s, "", "wrk"))
124}