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 | |
| 11 | func (s *Veths2Suite) TestLDPreloadIperfVpp() { |
| 12 | 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 Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame^] | 50 | _, err = hstExec("Configure2Veths srv", srvInstance) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 51 | if err != nil { |
| 52 | t.Errorf("%v", err) |
| 53 | return |
| 54 | } |
| 55 | |
Filip Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame^] | 56 | _, err = hstExec("Configure2Veths cln", clnInstance) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 57 | 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 Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame^] | 69 | 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] | 70 | 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 Tehlar | 1a9dc75 | 2022-11-22 12:49:22 +0100 | [diff] [blame^] | 83 | 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] | 84 | 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 | } |