blob: 22f82c191a58fe23a6dc2a8b5b4e502c5abf13b5 [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 Tehlarc204c872022-12-21 08:59:16 +01006)
7
Filip Tehlarb15a0002022-11-10 12:34:17 +01008func (s *NsSuite) TestHttpTps() {
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +01009 iface := s.netInterfaces[clientInterface]
Maros Ondrejickae7625d02023-02-28 16:55:01 +010010 client_ip := iface.ip4AddressString()
Filip Tehlarb15a0002022-11-10 12:34:17 +010011 port := "8080"
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010012 finished := make(chan error, 1)
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010013
14 container := s.getContainerByName("vpp")
Filip Tehlarb15a0002022-11-10 12:34:17 +010015
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010016 // configure vpp in the container
17 container.vppInstance.vppctl("http tps uri tcp://0.0.0.0/8080")
Filip Tehlarb15a0002022-11-10 12:34:17 +010018
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010019 go startWget(finished, client_ip, port, "test_file_10M", "client")
Filip Tehlarb15a0002022-11-10 12:34:17 +010020 // wait for client
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010021 err := <-finished
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010022 s.assertNil(err)
Filip Tehlarb15a0002022-11-10 12:34:17 +010023}
24
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010025func (s *VethsSuite) TestHttpCli() {
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010026 serverContainer := s.getContainerByName("server-vpp")
27 clientContainer := s.getContainerByName("client-vpp")
Filip Tehlarb15a0002022-11-10 12:34:17 +010028
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010029 serverVeth := s.netInterfaces[serverInterfaceName]
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010030
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010031 serverContainer.vppInstance.vppctl("http cli server")
Filip Tehlarb15a0002022-11-10 12:34:17 +010032
Maros Ondrejickae7625d02023-02-28 16:55:01 +010033 uri := "http://" + serverVeth.ip4AddressString() + "/80"
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010034
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010035 o := clientContainer.vppInstance.vppctl("http cli client" +
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010036 " uri " + uri + " query /show/version")
Filip Tehlarb15a0002022-11-10 12:34:17 +010037
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010038 s.log(o)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010039 s.assertContains(o, "<html>", "<html> not found in the result!")
Filip Tehlarb15a0002022-11-10 12:34:17 +010040}
Filip Tehlarc204c872022-12-21 08:59:16 +010041
Maros Ondrejickaad406072023-02-24 14:16:25 +010042func (s *NoTopoSuite) TestNginxAsServer() {
Filip Tehlarc204c872022-12-21 08:59:16 +010043 query := "return_ok"
44 finished := make(chan error, 1)
Filip Tehlarc204c872022-12-21 08:59:16 +010045
46 nginxCont := s.getContainerByName("nginx")
47 s.assertNil(nginxCont.run())
48
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010049 vpp := s.getContainerByName("vpp").vppInstance
Florin Corase2415f72023-02-28 14:51:03 -080050 vpp.waitForApp("nginx-", 5)
Filip Tehlarc204c872022-12-21 08:59:16 +010051
Maros Ondrejickae7625d02023-02-28 16:55:01 +010052 serverAddress := s.netInterfaces[tapInterfaceName].peer.ip4AddressString()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010053
Filip Tehlarc204c872022-12-21 08:59:16 +010054 defer func() { os.Remove(query) }()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010055 go startWget(finished, serverAddress, "80", query, "")
Filip Tehlarc204c872022-12-21 08:59:16 +010056 s.assertNil(<-finished)
57}
Filip Tehlar8df3de42023-01-27 13:14:34 +010058
59func runNginxPerf(s *NoTopoSuite, mode, ab_or_wrk string) error {
60 nRequests := 1000000
61 nClients := 2000
Filip Tehlar8df3de42023-01-27 13:14:34 +010062
Maros Ondrejickae7625d02023-02-28 16:55:01 +010063 serverAddress := s.netInterfaces[tapInterfaceName].peer.ip4AddressString()
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010064
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010065 vpp := s.getContainerByName("vpp").vppInstance
Filip Tehlar8df3de42023-01-27 13:14:34 +010066
67 nginxCont := s.getContainerByName("nginx")
68 s.assertNil(nginxCont.run())
Florin Corase2415f72023-02-28 14:51:03 -080069 vpp.waitForApp("nginx-", 5)
Filip Tehlar8df3de42023-01-27 13:14:34 +010070
Filip Tehlarb41b0af2023-03-20 12:39:20 +010071 if ab_or_wrk == "ab" {
72 abCont := s.getContainerByName("ab")
73 args := fmt.Sprintf("-n %d -c %d", nRequests, nClients)
74 if mode == "rps" {
75 args += " -k"
76 } else if mode != "cps" {
77 return fmt.Errorf("invalid mode %s; expected cps/rps", mode)
78 }
79 args += " http://" + serverAddress + ":80/64B.json"
80 abCont.extraRunningArgs = args
81 o, err := abCont.combinedOutput()
82 s.log(o, err)
83 s.assertNil(err)
84 } else {
85 wrkCont := s.getContainerByName("wrk")
86 args := fmt.Sprintf("-c %d -t 2 -d 30 http://%s:80/64B.json", nClients,
87 serverAddress)
88 wrkCont.extraRunningArgs = args
89 o, err := wrkCont.combinedOutput()
90 s.log(o)
91 s.assertNil(err)
92 }
Filip Tehlar8df3de42023-01-27 13:14:34 +010093 return nil
94}
95
96func (s *NoTopoSuite) TestNginxPerfCps() {
97 s.assertNil(runNginxPerf(s, "cps", "ab"))
98}
99
100func (s *NoTopoSuite) TestNginxPerfRps() {
101 s.assertNil(runNginxPerf(s, "rps", "ab"))
102}
103
104func (s *NoTopoSuite) TestNginxPerfWrk() {
105 s.assertNil(runNginxPerf(s, "", "wrk"))
106}