blob: 53043aabaf2bfcaa1ad2506fbf2ce57e96eef11d [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
Adrian Villin4677d922024-06-14 09:32:39 +02007 . "fd.io/hs-test/infra"
Adrian Villincee15aa2024-03-14 11:42:55 -04008 . "github.com/onsi/ginkgo/v2"
Filip Tehlar229f5fc2022-08-09 14:44:47 +00009)
10
Adrian Villincee15aa2024-03-14 11:42:55 -040011func init() {
Adrian Villin4677d922024-06-14 09:32:39 +020012 RegisterVethTests(LDPreloadIperfVppTest)
Adrian Villincee15aa2024-03-14 11:42:55 -040013}
14
15func LDPreloadIperfVppTest(s *VethsSuite) {
Filip Tehlar229f5fc2022-08-09 14:44:47 +000016 var clnVclConf, srvVclConf Stanza
Adrian Villinb4516bb2024-06-19 06:20:00 -040017 var ldpreload string
Filip Tehlar229f5fc2022-08-09 14:44:47 +000018
Adrian Villin4677d922024-06-14 09:32:39 +020019 serverContainer := s.GetContainerByName("server-vpp")
20 serverVclFileName := serverContainer.GetHostWorkDir() + "/vcl_srv.conf"
Filip Tehlar229f5fc2022-08-09 14:44:47 +000021
Adrian Villin4677d922024-06-14 09:32:39 +020022 clientContainer := s.GetContainerByName("client-vpp")
23 clientVclFileName := clientContainer.GetHostWorkDir() + "/vcl_cln.conf"
Filip Tehlar229f5fc2022-08-09 14:44:47 +000024
Adrian Villinb4516bb2024-06-19 06:20:00 -040025 if *IsDebugBuild {
26 ldpreload = "LD_PRELOAD=../../build-root/build-vpp_debug-native/vpp/lib/x86_64-linux-gnu/libvcl_ldpreload.so"
27 } else {
28 ldpreload = "LD_PRELOAD=../../build-root/build-vpp-native/vpp/lib/x86_64-linux-gnu/libvcl_ldpreload.so"
29 }
Filip Tehlar229f5fc2022-08-09 14:44:47 +000030
31 stopServerCh := make(chan struct{}, 1)
32 srvCh := make(chan error, 1)
33 clnCh := make(chan error)
34
Adrian Villin4677d922024-06-14 09:32:39 +020035 s.Log("starting VPPs")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000036
Filip Tehlar5ebdd512023-12-14 13:06:54 +010037 clientAppSocketApi := fmt.Sprintf("app-socket-api %s/var/run/app_ns_sockets/default",
Adrian Villin4677d922024-06-14 09:32:39 +020038 clientContainer.GetHostWorkDir())
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010039 err := clnVclConf.
Adrian Villin4677d922024-06-14 09:32:39 +020040 NewStanza("vcl").
41 Append("rx-fifo-size 4000000").
42 Append("tx-fifo-size 4000000").
43 Append("app-scope-local").
44 Append("app-scope-global").
45 Append("use-mq-eventfd").
46 Append(clientAppSocketApi).Close().
47 SaveToFile(clientVclFileName)
48 s.AssertNil(err, fmt.Sprint(err))
Filip Tehlar229f5fc2022-08-09 14:44:47 +000049
Filip Tehlar5ebdd512023-12-14 13:06:54 +010050 serverAppSocketApi := fmt.Sprintf("app-socket-api %s/var/run/app_ns_sockets/default",
Adrian Villin4677d922024-06-14 09:32:39 +020051 serverContainer.GetHostWorkDir())
Filip Tehlar229f5fc2022-08-09 14:44:47 +000052 err = srvVclConf.
Adrian Villin4677d922024-06-14 09:32:39 +020053 NewStanza("vcl").
54 Append("rx-fifo-size 4000000").
55 Append("tx-fifo-size 4000000").
56 Append("app-scope-local").
57 Append("app-scope-global").
58 Append("use-mq-eventfd").
59 Append(serverAppSocketApi).Close().
60 SaveToFile(serverVclFileName)
61 s.AssertNil(err, fmt.Sprint(err))
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010062
Adrian Villin4677d922024-06-14 09:32:39 +020063 s.Log("attaching server to vpp")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000064
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010065 srvEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+serverVclFileName)
Adrian Villincee15aa2024-03-14 11:42:55 -040066 go func() {
67 defer GinkgoRecover()
Adrian Villin4677d922024-06-14 09:32:39 +020068 s.StartServerApp(srvCh, stopServerCh, srvEnv)
Adrian Villincee15aa2024-03-14 11:42:55 -040069 }()
Filip Tehlar229f5fc2022-08-09 14:44:47 +000070
71 err = <-srvCh
Adrian Villin4677d922024-06-14 09:32:39 +020072 s.AssertNil(err, fmt.Sprint(err))
Filip Tehlar229f5fc2022-08-09 14:44:47 +000073
Adrian Villin4677d922024-06-14 09:32:39 +020074 s.Log("attaching client to vpp")
Maros Ondrejicka87531802022-12-19 20:35:27 +010075 var clnRes = make(chan string, 1)
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010076 clnEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+clientVclFileName)
Adrian Villin4677d922024-06-14 09:32:39 +020077 serverVethAddress := s.GetInterfaceByName(ServerInterfaceName).Ip4AddressString()
Adrian Villincee15aa2024-03-14 11:42:55 -040078 go func() {
79 defer GinkgoRecover()
Adrian Villin4677d922024-06-14 09:32:39 +020080 s.StartClientApp(serverVethAddress, clnEnv, clnCh, clnRes)
Adrian Villincee15aa2024-03-14 11:42:55 -040081 }()
Adrian Villin4677d922024-06-14 09:32:39 +020082 s.Log(<-clnRes)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000083
84 // wait for client's result
85 err = <-clnCh
Adrian Villin4677d922024-06-14 09:32:39 +020086 s.AssertNil(err, fmt.Sprint(err))
Filip Tehlar229f5fc2022-08-09 14:44:47 +000087
88 // stop server
89 stopServerCh <- struct{}{}
90}