blob: 683c6a3752574ce411b0b573505b924c28829d81 [file] [log] [blame]
Filip Tehlar229f5fc2022-08-09 14:44:47 +00001package main
2
3import (
4 "fmt"
5 "os"
6 "time"
7
8 "github.com/edwarnicke/exechelper"
9)
10
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010011func (s *VethsSuite) TestLDPreloadIperfVpp() {
Filip Tehlar229f5fc2022-08-09 14:44:47 +000012 var clnVclConf, srvVclConf Stanza
13
14 srvInstance := "vpp-ldp-srv"
15 clnInstance := "vpp-ldp-cln"
16 srvPath := "/tmp/" + srvInstance
17 clnPath := "/tmp/" + clnInstance
18 srvVcl := srvPath + "/vcl_srv.conf"
19 clnVcl := clnPath + "/vcl_cln.conf"
20
21 exechelper.Run("mkdir " + srvPath)
22 exechelper.Run("mkdir " + clnPath)
23
24 ldpreload := os.Getenv("HST_LDPRELOAD")
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010025 s.assertNotEqual("", ldpreload)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000026
27 ldpreload = "LD_PRELOAD=" + ldpreload
28
29 stopServerCh := make(chan struct{}, 1)
30 srvCh := make(chan error, 1)
31 clnCh := make(chan error)
32
33 fmt.Println("starting VPPs")
34
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010035 s.assertNil(dockerRun(srvInstance, fmt.Sprintf("-v /tmp/%s:/tmp", srvInstance)), "failed to start docker (srv)")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000036 defer func() { exechelper.Run("docker stop " + srvInstance) }()
37
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010038 s.assertNil(dockerRun(clnInstance, fmt.Sprintf("-v /tmp/%s:/tmp", clnInstance)), "failed to start docker (cln)")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000039 defer func() { exechelper.Run("docker stop " + clnInstance) }()
40
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010041 _, err := hstExec("Configure2Veths srv", srvInstance)
42 s.assertNil(err)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000043
Filip Tehlar1a9dc752022-11-22 12:49:22 +010044 _, err = hstExec("Configure2Veths cln", clnInstance)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010045 s.assertNil(err)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000046
47 err = clnVclConf.
48 NewStanza("vcl").
49 Append("rx-fifo-size 4000000").
50 Append("tx-fifo-size 4000000").
51 Append("app-scope-local").
52 Append("app-scope-global").
53 Append("use-mq-eventfd").
Filip Tehlar1a9dc752022-11-22 12:49:22 +010054 Append(fmt.Sprintf("app-socket-api /tmp/%s/Configure2Veths/var/run/app_ns_sockets/2", clnInstance)).Close().
Filip Tehlar229f5fc2022-08-09 14:44:47 +000055 SaveToFile(clnVcl)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010056 s.assertNil(err)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000057
58 err = srvVclConf.
59 NewStanza("vcl").
60 Append("rx-fifo-size 4000000").
61 Append("tx-fifo-size 4000000").
62 Append("app-scope-local").
63 Append("app-scope-global").
64 Append("use-mq-eventfd").
Filip Tehlar1a9dc752022-11-22 12:49:22 +010065 Append(fmt.Sprintf("app-socket-api /tmp/%s/Configure2Veths/var/run/app_ns_sockets/1", srvInstance)).Close().
Filip Tehlar229f5fc2022-08-09 14:44:47 +000066 SaveToFile(srvVcl)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010067 s.assertNil(err)
68
Filip Tehlar229f5fc2022-08-09 14:44:47 +000069 fmt.Printf("attaching server to vpp")
70
71 // FIXME
72 time.Sleep(5 * time.Second)
73
74 srvEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+srvVcl)
75 go StartServerApp(srvCh, stopServerCh, srvEnv)
76
77 err = <-srvCh
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010078 s.assertNil(err)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000079
80 fmt.Println("attaching client to vpp")
81 clnEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+clnVcl)
82 go StartClientApp(clnEnv, clnCh)
83
84 // wait for client's result
85 err = <-clnCh
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010086 s.assertNil(err)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000087
88 // stop server
89 stopServerCh <- struct{}{}
90}