blob: 96985be1ca7c6a649032e939fb64b575b935c0da [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"
Filip Tehlarc204c872022-12-21 08:59:16 +01007)
8
Filip Tehlarb15a0002022-11-10 12:34:17 +01009func (s *NsSuite) TestHttpTps() {
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010010 iface := s.netInterfaces[clientInterface]
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010011 client_ip := iface.IP4AddressString()
Filip Tehlarb15a0002022-11-10 12:34:17 +010012 port := "8080"
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010013 finished := make(chan error, 1)
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010014
15 container := s.getContainerByName("vpp")
Filip Tehlarb15a0002022-11-10 12:34:17 +010016
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010017 // configure vpp in the container
18 container.vppInstance.vppctl("http tps uri tcp://0.0.0.0/8080")
Filip Tehlarb15a0002022-11-10 12:34:17 +010019
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010020 go startWget(finished, client_ip, port, "test_file_10M", "client")
Filip Tehlarb15a0002022-11-10 12:34:17 +010021 // wait for client
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010022 err := <-finished
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010023 s.assertNil(err)
Filip Tehlarb15a0002022-11-10 12:34:17 +010024}
25
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010026func (s *VethsSuite) TestHttpCli() {
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010027 serverContainer := s.getContainerByName("server-vpp")
28 clientContainer := s.getContainerByName("client-vpp")
Filip Tehlarb15a0002022-11-10 12:34:17 +010029
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010030 serverVeth := s.netInterfaces[serverInterfaceName]
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010031
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010032 serverContainer.vppInstance.vppctl("http cli server")
Filip Tehlarb15a0002022-11-10 12:34:17 +010033
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010034 uri := "http://" + serverVeth.IP4AddressString() + "/80"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010035
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010036 o := clientContainer.vppInstance.vppctl("http cli client" +
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010037 " uri " + uri + " query /show/version")
Filip Tehlarb15a0002022-11-10 12:34:17 +010038
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010039 s.log(o)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010040 s.assertContains(o, "<html>", "<html> not found in the result!")
Filip Tehlarb15a0002022-11-10 12:34:17 +010041}
Filip Tehlarc204c872022-12-21 08:59:16 +010042
Maros Ondrejickaad406072023-02-24 14:16:25 +010043func (s *NoTopoSuite) TestNginxAsServer() {
Filip Tehlarc204c872022-12-21 08:59:16 +010044 query := "return_ok"
45 finished := make(chan error, 1)
Filip Tehlarc204c872022-12-21 08:59:16 +010046
47 nginxCont := s.getContainerByName("nginx")
48 s.assertNil(nginxCont.run())
49
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010050 vpp := s.getContainerByName("vpp").vppInstance
51 err := vpp.waitForApp("-app", 5)
Filip Tehlar8df3de42023-01-27 13:14:34 +010052 s.assertNil(err)
Filip Tehlarc204c872022-12-21 08:59:16 +010053
Maros Ondrejicka40cba402023-02-23 13:19:15 +010054 serverAddress := s.netInterfaces[tapInterfaceName].Peer().IP4AddressString()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010055
Filip Tehlarc204c872022-12-21 08:59:16 +010056 defer func() { os.Remove(query) }()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010057 go startWget(finished, serverAddress, "80", query, "")
Filip Tehlarc204c872022-12-21 08:59:16 +010058 s.assertNil(<-finished)
59}
Filip Tehlar8df3de42023-01-27 13:14:34 +010060
61func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string) error {
62 nRequests := 1000000
63 nClients := 2000
64 var args []string
65 var exeName string
66
Maros Ondrejicka40cba402023-02-23 13:19:15 +010067 serverAddress := s.netInterfaces[tapInterfaceName].Peer().IP4AddressString()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010068
Filip Tehlar8df3de42023-01-27 13:14:34 +010069 if ab_or_wrk == "ab" {
70 args = []string{"-n", fmt.Sprintf("%d", nRequests), "-c",
71 fmt.Sprintf("%d", nClients)}
72 if mode == "rps" {
73 args = append(args, "-k")
74 } else if mode != "cps" {
75 return fmt.Errorf("invalid mode %s; expected cps/rps", mode)
76 }
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010077 args = append(args, "http://"+serverAddress+":80/64B.json")
Filip Tehlar8df3de42023-01-27 13:14:34 +010078 exeName = "ab"
79 } else {
80 args = []string{"-c", fmt.Sprintf("%d", nClients), "-t", "2", "-d", "30",
Maros Ondrejickaad406072023-02-24 14:16:25 +010081 "http://" + serverAddress + ":80/64B.json"}
Filip Tehlar8df3de42023-01-27 13:14:34 +010082 exeName = "wrk"
83 }
84
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010085 vpp := s.getContainerByName("vpp").vppInstance
Filip Tehlar8df3de42023-01-27 13:14:34 +010086
87 nginxCont := s.getContainerByName("nginx")
88 s.assertNil(nginxCont.run())
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010089 err := vpp.waitForApp("-app", 5)
Filip Tehlar8df3de42023-01-27 13:14:34 +010090 s.assertNil(err)
91
92 cmd := exec.Command(exeName, args...)
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010093 s.log(cmd)
Filip Tehlar8df3de42023-01-27 13:14:34 +010094 o, _ := cmd.CombinedOutput()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010095 s.log(string(o))
Maros Ondrejicka2ddb2fd2023-02-15 17:44:46 +010096 s.assertNotEmpty(o)
Filip Tehlar8df3de42023-01-27 13:14:34 +010097 return nil
98}
99
100func (s *NoTopoSuite) TestNginxPerfCps() {
101 s.assertNil(runNginxPerf(s, "cps", "ab"))
102}
103
104func (s *NoTopoSuite) TestNginxPerfRps() {
105 s.assertNil(runNginxPerf(s, "rps", "ab"))
106}
107
108func (s *NoTopoSuite) TestNginxPerfWrk() {
109 s.assertNil(runNginxPerf(s, "", "wrk"))
110}