blob: c219c82ea502ab7e1e3d6a562350af71eba0b495 [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 t := s.T()
13 var clnVclConf, srvVclConf Stanza
14
15 srvInstance := "vpp-ldp-srv"
16 clnInstance := "vpp-ldp-cln"
17 srvPath := "/tmp/" + srvInstance
18 clnPath := "/tmp/" + clnInstance
19 srvVcl := srvPath + "/vcl_srv.conf"
20 clnVcl := clnPath + "/vcl_cln.conf"
21
22 exechelper.Run("mkdir " + srvPath)
23 exechelper.Run("mkdir " + clnPath)
24
25 ldpreload := os.Getenv("HST_LDPRELOAD")
26 s.Assert().NotEqual("", ldpreload)
27
28 ldpreload = "LD_PRELOAD=" + ldpreload
29
30 stopServerCh := make(chan struct{}, 1)
31 srvCh := make(chan error, 1)
32 clnCh := make(chan error)
33
34 fmt.Println("starting VPPs")
35
36 err := dockerRun(srvInstance, fmt.Sprintf("-v /tmp/%s:/tmp", srvInstance))
37 if err != nil {
38 t.Errorf("%v", err)
39 return
40 }
41 defer func() { exechelper.Run("docker stop " + srvInstance) }()
42
43 err = dockerRun(clnInstance, fmt.Sprintf("-v /tmp/%s:/tmp", clnInstance))
44 if err != nil {
45 t.Errorf("%v", err)
46 return
47 }
48 defer func() { exechelper.Run("docker stop " + clnInstance) }()
49
Filip Tehlar1a9dc752022-11-22 12:49:22 +010050 _, err = hstExec("Configure2Veths srv", srvInstance)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000051 if err != nil {
52 t.Errorf("%v", err)
53 return
54 }
55
Filip Tehlar1a9dc752022-11-22 12:49:22 +010056 _, err = hstExec("Configure2Veths cln", clnInstance)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000057 if err != nil {
58 t.Errorf("%v", err)
59 return
60 }
61
62 err = clnVclConf.
63 NewStanza("vcl").
64 Append("rx-fifo-size 4000000").
65 Append("tx-fifo-size 4000000").
66 Append("app-scope-local").
67 Append("app-scope-global").
68 Append("use-mq-eventfd").
Filip Tehlar1a9dc752022-11-22 12:49:22 +010069 Append(fmt.Sprintf("app-socket-api /tmp/%s/Configure2Veths/var/run/app_ns_sockets/2", clnInstance)).Close().
Filip Tehlar229f5fc2022-08-09 14:44:47 +000070 SaveToFile(clnVcl)
71 if err != nil {
72 t.Errorf("%v", err)
73 t.FailNow()
74 }
75
76 err = srvVclConf.
77 NewStanza("vcl").
78 Append("rx-fifo-size 4000000").
79 Append("tx-fifo-size 4000000").
80 Append("app-scope-local").
81 Append("app-scope-global").
82 Append("use-mq-eventfd").
Filip Tehlar1a9dc752022-11-22 12:49:22 +010083 Append(fmt.Sprintf("app-socket-api /tmp/%s/Configure2Veths/var/run/app_ns_sockets/1", srvInstance)).Close().
Filip Tehlar229f5fc2022-08-09 14:44:47 +000084 SaveToFile(srvVcl)
85 if err != nil {
86 t.Errorf("%v", err)
87 t.FailNow()
88 }
89 fmt.Printf("attaching server to vpp")
90
91 // FIXME
92 time.Sleep(5 * time.Second)
93
94 srvEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+srvVcl)
95 go StartServerApp(srvCh, stopServerCh, srvEnv)
96
97 err = <-srvCh
98 if err != nil {
99 s.FailNow("vcl server", "%v", err)
100 }
101
102 fmt.Println("attaching client to vpp")
103 clnEnv := append(os.Environ(), ldpreload, "VCL_CONFIG="+clnVcl)
104 go StartClientApp(clnEnv, clnCh)
105
106 // wait for client's result
107 err = <-clnCh
108 if err != nil {
109 s.Failf("client", "%v", err)
110 }
111
112 // stop server
113 stopServerCh <- struct{}{}
114}