blob: 585f4981681c5bca18987f80f4f77bca8b8f59e2 [file] [log] [blame]
Filip Tehlar229f5fc2022-08-09 14:44:47 +00001package main
2
3import (
4 "fmt"
Adrian Villin514098e2024-10-15 14:56:16 +02005 "time"
Adrian Villincee15aa2024-03-14 11:42:55 -04006
Adrian Villin4677d922024-06-14 09:32:39 +02007 . "fd.io/hs-test/infra"
Adrian Villincee15aa2024-03-14 11:42:55 -04008 . "github.com/onsi/ginkgo/v2"
Filip Tehlar229f5fc2022-08-09 14:44:47 +00009)
10
Adrian Villincee15aa2024-03-14 11:42:55 -040011func init() {
Adrian Villin36283532024-11-27 09:47:44 +010012 RegisterLdpTests(LdpIperfUdpVppTest, LdpIperfUdpVppInterruptModeTest, RedisBenchmarkTest, LdpIperfTlsTcpTest, LdpIperfTcpVppTest)
Adrian Villin1fde9992024-06-24 08:14:05 -040013}
14
Adrian Villin36283532024-11-27 09:47:44 +010015func LdpIperfUdpVppInterruptModeTest(s *LdpSuite) {
Adrian Villinff363072024-11-21 12:21:24 +010016 ldPreloadIperfVpp(s, true)
17}
18
Adrian Villin36283532024-11-27 09:47:44 +010019func LdpIperfTlsTcpTest(s *LdpSuite) {
Adrian Villinff363072024-11-21 12:21:24 +010020 for _, c := range s.Containers {
Adrian Villin36283532024-11-27 09:47:44 +010021 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 Villinff363072024-11-21 12:21:24 +010024 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 Villincee15aa2024-03-14 11:42:55 -040030}
31
Adrian Villin36283532024-11-27 09:47:44 +010032func LdpIperfTcpVppTest(s *LdpSuite) {
33 ldPreloadIperfVpp(s, false)
34}
35
36func LdpIperfUdpVppTest(s *LdpSuite) {
Adrian Villinff363072024-11-21 12:21:24 +010037 ldPreloadIperfVpp(s, true)
38}
39
40func ldPreloadIperfVpp(s *LdpSuite, useUdp bool) {
41 protocol := ""
42 if useUdp {
43 protocol = " -u "
44 }
Adrian Villin4677d922024-06-14 09:32:39 +020045 clientContainer := s.GetContainerByName("client-vpp")
Adrian Villind01a63a2024-08-15 12:53:53 +020046 serverContainer := s.GetContainerByName("server-vpp")
Adrian Villinff363072024-11-21 12:21:24 +010047 serverVethAddress := s.GetInterfaceByName(ServerInterfaceName).Ip4AddressString()
Filip Tehlar229f5fc2022-08-09 14:44:47 +000048 stopServerCh := make(chan struct{}, 1)
49 srvCh := make(chan error, 1)
50 clnCh := make(chan error)
Adrian Villin8b2a67c2024-12-06 16:00:25 +010051 clnRes := make(chan []byte, 1)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000052
Adrian Villin514098e2024-10-15 14:56:16 +020053 defer func() {
54 stopServerCh <- struct{}{}
55 }()
56
Adrian Villincee15aa2024-03-14 11:42:55 -040057 go func() {
58 defer GinkgoRecover()
Adrian Villind01a63a2024-08-15 12:53:53 +020059 cmd := "iperf3 -4 -s -p " + s.GetPortFromPpid()
60 s.StartServerApp(serverContainer, "iperf3", cmd, srvCh, stopServerCh)
Adrian Villincee15aa2024-03-14 11:42:55 -040061 }()
Filip Tehlar229f5fc2022-08-09 14:44:47 +000062
Adrian Villind01a63a2024-08-15 12:53:53 +020063 err := <-srvCh
Adrian Villin4677d922024-06-14 09:32:39 +020064 s.AssertNil(err, fmt.Sprint(err))
Filip Tehlar229f5fc2022-08-09 14:44:47 +000065
Adrian Villincee15aa2024-03-14 11:42:55 -040066 go func() {
67 defer GinkgoRecover()
Adrian Villin8b2a67c2024-12-06 16:00:25 +010068 cmd := "iperf3 -c " + serverVethAddress + " -l 1460 -b 10g -J -p " + s.GetPortFromPpid() + protocol
Adrian Villind01a63a2024-08-15 12:53:53 +020069 s.StartClientApp(clientContainer, cmd, clnCh, clnRes)
Adrian Villincee15aa2024-03-14 11:42:55 -040070 }()
Adrian Villin514098e2024-10-15 14:56:16 +020071
72 s.AssertChannelClosed(time.Minute*3, clnCh)
Adrian Villin8b2a67c2024-12-06 16:00:25 +010073 output := <-clnRes
74 result := s.ParseJsonIperfOutput(output)
75 s.LogJsonIperfOutput(result)
76 s.AssertIperfMinTransfer(result, 400)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000077}
Adrian Villind01a63a2024-08-15 12:53:53 +020078
79func RedisBenchmarkTest(s *LdpSuite) {
80 s.SkipIfMultiWorker()
Matus Fabianc4b4cd52024-12-08 15:13:44 +010081 s.SkipIfArm()
Adrian Villind01a63a2024-08-15 12:53:53 +020082
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 Villin8b2a67c2024-12-06 16:00:25 +010090 clnRes := make(chan []byte, 1)
Adrian Villind01a63a2024-08-15 12:53:53 +020091
Adrian Villin514098e2024-10-15 14:56:16 +020092 defer func() {
93 doneSrv <- struct{}{}
94 }()
95
Adrian Villind01a63a2024-08-15 12:53:53 +020096 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 Villin514098e2024-10-15 14:56:16 +0200114
Adrian Villind01a63a2024-08-15 12:53:53 +0200115 }()
116
Adrian Villin514098e2024-10-15 14:56:16 +0200117 // 4.5 minutes
118 s.AssertChannelClosed(time.Second*270, clnCh)
Adrian Villin8b2a67c2024-12-06 16:00:25 +0100119 s.Log(string(<-clnRes))
Adrian Villind01a63a2024-08-15 12:53:53 +0200120}