blob: 24d2de3948596a718a527bac021bdca4744487ca [file] [log] [blame]
Filip Tehlar229f5fc2022-08-09 14:44:47 +00001package main
2
3import (
4 "fmt"
5 "os"
Adrian Villincee15aa2024-03-14 11:42:55 -04006
7 . "github.com/onsi/ginkgo/v2"
Filip Tehlar229f5fc2022-08-09 14:44:47 +00008)
9
Adrian Villincee15aa2024-03-14 11:42:55 -040010func init() {
11 registerVethTests(LDPreloadIperfVppTest)
12}
13
14func LDPreloadIperfVppTest(s *VethsSuite) {
Filip Tehlar229f5fc2022-08-09 14:44:47 +000015 var clnVclConf, srvVclConf Stanza
16
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010017 serverContainer := s.getContainerByName("server-vpp")
Maros Ondrejickae7625d02023-02-28 16:55:01 +010018 serverVclFileName := serverContainer.getHostWorkDir() + "/vcl_srv.conf"
Filip Tehlar229f5fc2022-08-09 14:44:47 +000019
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010020 clientContainer := s.getContainerByName("client-vpp")
Maros Ondrejickae7625d02023-02-28 16:55:01 +010021 clientVclFileName := clientContainer.getHostWorkDir() + "/vcl_cln.conf"
Filip Tehlar229f5fc2022-08-09 14:44:47 +000022
Adrian Villincee15aa2024-03-14 11:42:55 -040023 ldpreload := "LD_PRELOAD=../../build-root/build-vpp-native/vpp/lib/x86_64-linux-gnu/libvcl_ldpreload.so"
Filip Tehlar229f5fc2022-08-09 14:44:47 +000024
25 stopServerCh := make(chan struct{}, 1)
26 srvCh := make(chan error, 1)
27 clnCh := make(chan error)
28
Maros Ondrejicka87531802022-12-19 20:35:27 +010029 s.log("starting VPPs")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000030
Filip Tehlar5ebdd512023-12-14 13:06:54 +010031 clientAppSocketApi := fmt.Sprintf("app-socket-api %s/var/run/app_ns_sockets/default",
Filip Tehlara1bd50c2024-01-24 11:59:44 +010032 clientContainer.getHostWorkDir())
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010033 err := clnVclConf.
Maros Ondrejickae7625d02023-02-28 16:55:01 +010034 newStanza("vcl").
35 append("rx-fifo-size 4000000").
36 append("tx-fifo-size 4000000").
37 append("app-scope-local").
38 append("app-scope-global").
39 append("use-mq-eventfd").
40 append(clientAppSocketApi).close().
41 saveToFile(clientVclFileName)
Adrian Villincee15aa2024-03-14 11:42:55 -040042 s.assertNil(err, fmt.Sprint(err))
Filip Tehlar229f5fc2022-08-09 14:44:47 +000043
Filip Tehlar5ebdd512023-12-14 13:06:54 +010044 serverAppSocketApi := fmt.Sprintf("app-socket-api %s/var/run/app_ns_sockets/default",
Filip Tehlara1bd50c2024-01-24 11:59:44 +010045 serverContainer.getHostWorkDir())
Filip Tehlar229f5fc2022-08-09 14:44:47 +000046 err = srvVclConf.
Maros Ondrejickae7625d02023-02-28 16:55:01 +010047 newStanza("vcl").
48 append("rx-fifo-size 4000000").
49 append("tx-fifo-size 4000000").
50 append("app-scope-local").
51 append("app-scope-global").
52 append("use-mq-eventfd").
53 append(serverAppSocketApi).close().
54 saveToFile(serverVclFileName)
Adrian Villincee15aa2024-03-14 11:42:55 -040055 s.assertNil(err, fmt.Sprint(err))
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010056
Maros Ondrejicka87531802022-12-19 20:35:27 +010057 s.log("attaching server to vpp")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000058
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010059 srvEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+serverVclFileName)
Adrian Villincee15aa2024-03-14 11:42:55 -040060 go func() {
61 defer GinkgoRecover()
62 s.startServerApp(srvCh, stopServerCh, srvEnv)
63 }()
Filip Tehlar229f5fc2022-08-09 14:44:47 +000064
65 err = <-srvCh
Adrian Villincee15aa2024-03-14 11:42:55 -040066 s.assertNil(err, fmt.Sprint(err))
Filip Tehlar229f5fc2022-08-09 14:44:47 +000067
Maros Ondrejicka87531802022-12-19 20:35:27 +010068 s.log("attaching client to vpp")
69 var clnRes = make(chan string, 1)
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010070 clnEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+clientVclFileName)
adrianvillin28bd8f02024-02-13 06:00:02 -050071 serverVethAddress := s.getInterfaceByName(serverInterfaceName).ip4AddressString()
Adrian Villincee15aa2024-03-14 11:42:55 -040072 go func() {
73 defer GinkgoRecover()
74 s.startClientApp(serverVethAddress, clnEnv, clnCh, clnRes)
75 }()
Filip Tehlarf3ee2b62023-01-09 12:07:09 +010076 s.log(<-clnRes)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000077
78 // wait for client's result
79 err = <-clnCh
Adrian Villincee15aa2024-03-14 11:42:55 -040080 s.assertNil(err, fmt.Sprint(err))
Filip Tehlar229f5fc2022-08-09 14:44:47 +000081
82 // stop server
83 stopServerCh <- struct{}{}
84}