Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "os" |
| 6 | "time" |
| 7 | |
| 8 | "github.com/edwarnicke/exechelper" |
| 9 | ) |
| 10 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 11 | func (s *VethsSuite) TestLDPreloadIperfVpp() { |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 12 | 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 Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 25 | s.assertNotEqual("", ldpreload) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 26 | |
| 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 Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 35 | s.assertNil(dockerRun(srvInstance, fmt.Sprintf("-v /tmp/%s:/tmp", srvInstance)), "failed to start docker (srv)") |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 36 | defer func() { exechelper.Run("docker stop " + srvInstance) }() |
| 37 | |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 38 | s.assertNil(dockerRun(clnInstance, fmt.Sprintf("-v /tmp/%s:/tmp", clnInstance)), "failed to start docker (cln)") |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 39 | defer func() { exechelper.Run("docker stop " + clnInstance) }() |
| 40 | |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 41 | _, err := hstExec("Configure2Veths srv", srvInstance) |
| 42 | s.assertNil(err) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 43 | |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 44 | _, err = hstExec("Configure2Veths cln", clnInstance) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 45 | s.assertNil(err) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 46 | |
| 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 Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 54 | Append(fmt.Sprintf("app-socket-api /tmp/%s/Configure2Veths/var/run/app_ns_sockets/2", clnInstance)).Close(). |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 55 | SaveToFile(clnVcl) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 56 | s.assertNil(err) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 57 | |
| 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 Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame] | 65 | Append(fmt.Sprintf("app-socket-api /tmp/%s/Configure2Veths/var/run/app_ns_sockets/1", srvInstance)).Close(). |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 66 | SaveToFile(srvVcl) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 67 | s.assertNil(err) |
| 68 | |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 69 | 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 Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 78 | s.assertNil(err) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 79 | |
| 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 Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 86 | s.assertNil(err) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 87 | |
| 88 | // stop server |
| 89 | stopServerCh <- struct{}{} |
| 90 | } |