blob: 52b7c39fa77a1155e4cdb168f0eb8f1862ba918f [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() {
Filip Tehlarb15a0002022-11-10 12:34:17 +010012 finished := make(chan error, 1)
13 server_ip := "10.0.0.2"
14 port := "8080"
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010015
16 container := s.getContainerByName("vpp")
Filip Tehlarb15a0002022-11-10 12:34:17 +010017
Maros Ondrejicka87531802022-12-19 20:35:27 +010018 s.log("starting vpp..")
Filip Tehlarb15a0002022-11-10 12:34:17 +010019
Filip Tehlarb15a0002022-11-10 12:34:17 +010020 // start & configure vpp in the container
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010021 _, err := container.execAction("ConfigureHttpTps")
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010022 s.assertNil(err)
Filip Tehlarb15a0002022-11-10 12:34:17 +010023
Filip Tehlarc204c872022-12-21 08:59:16 +010024 go startWget(finished, server_ip, port, "test_file_10M", "client")
Filip Tehlarb15a0002022-11-10 12:34:17 +010025 // wait for client
26 err = <-finished
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010027 s.assertNil(err)
Filip Tehlarb15a0002022-11-10 12:34:17 +010028}
29
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010030func (s *VethsSuite) TestHttpCli() {
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010031 serverContainer := s.getContainerByName("server-vpp")
32 clientContainer := s.getContainerByName("client-vpp")
Filip Tehlarb15a0002022-11-10 12:34:17 +010033
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010034 serverVeth := s.veths["vppsrv"]
35
36 _, err := serverContainer.vppInstance.vppctl("http cli server")
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010037 s.assertNil(err)
Filip Tehlarb15a0002022-11-10 12:34:17 +010038
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010039 uri := "http://" + serverVeth.Address() + "/80"
40
41 o, err := clientContainer.vppInstance.vppctl("http cli client" +
42 " uri " + uri + " query /show/version")
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010043 s.assertNil(err)
Filip Tehlarb15a0002022-11-10 12:34:17 +010044
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010045 s.log(o)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010046 s.assertContains(o, "<html>", "<html> not found in the result!")
Filip Tehlarb15a0002022-11-10 12:34:17 +010047}
Filip Tehlarc204c872022-12-21 08:59:16 +010048
Filip Tehlar8df3de42023-01-27 13:14:34 +010049func 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 Tehlarc204c872022-12-21 08:59:16 +010063func (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 Tehlar8df3de42023-01-27 13:14:34 +010074 err := waitForApp(vppInst, "-app", 5)
75 s.assertNil(err)
Filip Tehlarc204c872022-12-21 08:59:16 +010076
77 defer func() { os.Remove(query) }()
78 go startWget(finished, "10.10.10.1", "80", query, "")
79 s.assertNil(<-finished)
80}
Filip Tehlar8df3de42023-01-27 13:14:34 +010081
82func 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
121func (s *NoTopoSuite) TestNginxPerfCps() {
122 s.assertNil(runNginxPerf(s, "cps", "ab"))
123}
124
125func (s *NoTopoSuite) TestNginxPerfRps() {
126 s.assertNil(runNginxPerf(s, "rps", "ab"))
127}
128
129func (s *NoTopoSuite) TestNginxPerfWrk() {
130 s.assertNil(runNginxPerf(s, "", "wrk"))
131}