Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
Adrian Villin | 514098e | 2024-10-15 14:56:16 +0200 | [diff] [blame] | 5 | "time" |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 6 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 7 | . "fd.io/hs-test/infra" |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 8 | . "github.com/onsi/ginkgo/v2" |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 9 | ) |
| 10 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 11 | func init() { |
Adrian Villin | 3628353 | 2024-11-27 09:47:44 +0100 | [diff] [blame] | 12 | RegisterLdpTests(LdpIperfUdpVppTest, LdpIperfUdpVppInterruptModeTest, RedisBenchmarkTest, LdpIperfTlsTcpTest, LdpIperfTcpVppTest) |
Adrian Villin | 1fde999 | 2024-06-24 08:14:05 -0400 | [diff] [blame] | 13 | } |
| 14 | |
Adrian Villin | 3628353 | 2024-11-27 09:47:44 +0100 | [diff] [blame] | 15 | func LdpIperfUdpVppInterruptModeTest(s *LdpSuite) { |
Adrian Villin | ff36307 | 2024-11-21 12:21:24 +0100 | [diff] [blame] | 16 | ldPreloadIperfVpp(s, true) |
| 17 | } |
| 18 | |
Adrian Villin | 3628353 | 2024-11-27 09:47:44 +0100 | [diff] [blame] | 19 | func LdpIperfTlsTcpTest(s *LdpSuite) { |
Adrian Villin | ff36307 | 2024-11-21 12:21:24 +0100 | [diff] [blame] | 20 | for _, c := range s.Containers { |
Adrian Villin | 3628353 | 2024-11-27 09:47:44 +0100 | [diff] [blame] | 21 | defer delete(c.EnvVars, "LDP_TRANSPARENT_TLS") |
| 22 | defer delete(c.EnvVars, "LDP_TLS_CERT_FILE") |
| 23 | defer delete(c.EnvVars, "LDP_TLS_KEY_FILE") |
Adrian Villin | ff36307 | 2024-11-21 12:21:24 +0100 | [diff] [blame] | 24 | c.Exec(false, "openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout key.key -out crt.crt -subj \"/CN=test\"") |
| 25 | c.AddEnvVar("LDP_TRANSPARENT_TLS", "1") |
| 26 | c.AddEnvVar("LDP_TLS_CERT_FILE", "/crt.crt") |
| 27 | c.AddEnvVar("LDP_TLS_KEY_FILE", "/key.key") |
| 28 | } |
| 29 | ldPreloadIperfVpp(s, false) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 30 | } |
| 31 | |
Adrian Villin | 3628353 | 2024-11-27 09:47:44 +0100 | [diff] [blame] | 32 | func LdpIperfTcpVppTest(s *LdpSuite) { |
| 33 | ldPreloadIperfVpp(s, false) |
| 34 | } |
| 35 | |
| 36 | func LdpIperfUdpVppTest(s *LdpSuite) { |
Adrian Villin | ff36307 | 2024-11-21 12:21:24 +0100 | [diff] [blame] | 37 | ldPreloadIperfVpp(s, true) |
| 38 | } |
| 39 | |
| 40 | func ldPreloadIperfVpp(s *LdpSuite, useUdp bool) { |
| 41 | protocol := "" |
| 42 | if useUdp { |
| 43 | protocol = " -u " |
| 44 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 45 | clientContainer := s.GetContainerByName("client-vpp") |
Adrian Villin | d01a63a | 2024-08-15 12:53:53 +0200 | [diff] [blame] | 46 | serverContainer := s.GetContainerByName("server-vpp") |
Adrian Villin | ff36307 | 2024-11-21 12:21:24 +0100 | [diff] [blame] | 47 | serverVethAddress := s.GetInterfaceByName(ServerInterfaceName).Ip4AddressString() |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 48 | stopServerCh := make(chan struct{}, 1) |
| 49 | srvCh := make(chan error, 1) |
| 50 | clnCh := make(chan error) |
Adrian Villin | 8b2a67c | 2024-12-06 16:00:25 +0100 | [diff] [blame] | 51 | clnRes := make(chan []byte, 1) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 52 | |
Adrian Villin | 514098e | 2024-10-15 14:56:16 +0200 | [diff] [blame] | 53 | defer func() { |
| 54 | stopServerCh <- struct{}{} |
| 55 | }() |
| 56 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 57 | go func() { |
| 58 | defer GinkgoRecover() |
Adrian Villin | d01a63a | 2024-08-15 12:53:53 +0200 | [diff] [blame] | 59 | cmd := "iperf3 -4 -s -p " + s.GetPortFromPpid() |
| 60 | s.StartServerApp(serverContainer, "iperf3", cmd, srvCh, stopServerCh) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 61 | }() |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 62 | |
Adrian Villin | d01a63a | 2024-08-15 12:53:53 +0200 | [diff] [blame] | 63 | err := <-srvCh |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 64 | s.AssertNil(err, fmt.Sprint(err)) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 65 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 66 | go func() { |
| 67 | defer GinkgoRecover() |
Adrian Villin | 8b2a67c | 2024-12-06 16:00:25 +0100 | [diff] [blame] | 68 | cmd := "iperf3 -c " + serverVethAddress + " -l 1460 -b 10g -J -p " + s.GetPortFromPpid() + protocol |
Adrian Villin | d01a63a | 2024-08-15 12:53:53 +0200 | [diff] [blame] | 69 | s.StartClientApp(clientContainer, cmd, clnCh, clnRes) |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 70 | }() |
Adrian Villin | 514098e | 2024-10-15 14:56:16 +0200 | [diff] [blame] | 71 | |
| 72 | s.AssertChannelClosed(time.Minute*3, clnCh) |
Adrian Villin | 8b2a67c | 2024-12-06 16:00:25 +0100 | [diff] [blame] | 73 | output := <-clnRes |
| 74 | result := s.ParseJsonIperfOutput(output) |
| 75 | s.LogJsonIperfOutput(result) |
| 76 | s.AssertIperfMinTransfer(result, 400) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 77 | } |
Adrian Villin | d01a63a | 2024-08-15 12:53:53 +0200 | [diff] [blame] | 78 | |
| 79 | func RedisBenchmarkTest(s *LdpSuite) { |
| 80 | s.SkipIfMultiWorker() |
Matus Fabian | c4b4cd5 | 2024-12-08 15:13:44 +0100 | [diff] [blame] | 81 | s.SkipIfArm() |
Adrian Villin | d01a63a | 2024-08-15 12:53:53 +0200 | [diff] [blame] | 82 | |
| 83 | serverContainer := s.GetContainerByName("server-vpp") |
| 84 | clientContainer := s.GetContainerByName("client-vpp") |
| 85 | |
| 86 | serverVethAddress := s.GetInterfaceByName(ServerInterfaceName).Ip4AddressString() |
| 87 | runningSrv := make(chan error) |
| 88 | doneSrv := make(chan struct{}) |
| 89 | clnCh := make(chan error) |
Adrian Villin | 8b2a67c | 2024-12-06 16:00:25 +0100 | [diff] [blame] | 90 | clnRes := make(chan []byte, 1) |
Adrian Villin | d01a63a | 2024-08-15 12:53:53 +0200 | [diff] [blame] | 91 | |
Adrian Villin | 514098e | 2024-10-15 14:56:16 +0200 | [diff] [blame] | 92 | defer func() { |
| 93 | doneSrv <- struct{}{} |
| 94 | }() |
| 95 | |
Adrian Villin | d01a63a | 2024-08-15 12:53:53 +0200 | [diff] [blame] | 96 | go func() { |
| 97 | defer GinkgoRecover() |
| 98 | cmd := "redis-server --daemonize yes --protected-mode no --bind " + serverVethAddress |
| 99 | s.StartServerApp(serverContainer, "redis-server", cmd, runningSrv, doneSrv) |
| 100 | }() |
| 101 | |
| 102 | err := <-runningSrv |
| 103 | s.AssertNil(err) |
| 104 | |
| 105 | go func() { |
| 106 | defer GinkgoRecover() |
| 107 | var cmd string |
| 108 | if *NConfiguredCpus == 1 { |
| 109 | cmd = "redis-benchmark --threads 1 -h " + serverVethAddress |
| 110 | } else { |
| 111 | cmd = "redis-benchmark --threads " + fmt.Sprint(*NConfiguredCpus) + "-h " + serverVethAddress |
| 112 | } |
| 113 | s.StartClientApp(clientContainer, cmd, clnCh, clnRes) |
Adrian Villin | 514098e | 2024-10-15 14:56:16 +0200 | [diff] [blame] | 114 | |
Adrian Villin | d01a63a | 2024-08-15 12:53:53 +0200 | [diff] [blame] | 115 | }() |
| 116 | |
Adrian Villin | 514098e | 2024-10-15 14:56:16 +0200 | [diff] [blame] | 117 | // 4.5 minutes |
| 118 | s.AssertChannelClosed(time.Second*270, clnCh) |
Adrian Villin | 8b2a67c | 2024-12-06 16:00:25 +0100 | [diff] [blame] | 119 | s.Log(string(<-clnRes)) |
Adrian Villin | d01a63a | 2024-08-15 12:53:53 +0200 | [diff] [blame] | 120 | } |