Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 1 | package main |
| 2 | |
| 3 | import ( |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 4 | . "fd.io/hs-test/infra" |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 5 | "fmt" |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 6 | "time" |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 7 | ) |
| 8 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 9 | func init() { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 10 | RegisterVethTests(XEchoVclClientUdpTest, XEchoVclClientTcpTest, XEchoVclServerUdpTest, |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 11 | XEchoVclServerTcpTest, VclEchoTcpTest, VclEchoUdpTest, VclRetryAttachTest) |
| 12 | } |
| 13 | |
Filip Tehlar | 5ebdd51 | 2023-12-14 13:06:54 +0100 | [diff] [blame] | 14 | func getVclConfig(c *Container, ns_id_optional ...string) string { |
| 15 | var s Stanza |
| 16 | ns_id := "default" |
| 17 | if len(ns_id_optional) > 0 { |
| 18 | ns_id = ns_id_optional[0] |
| 19 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 20 | s.NewStanza("vcl"). |
| 21 | Append(fmt.Sprintf("app-socket-api %[1]s/var/run/app_ns_sockets/%[2]s", c.GetContainerWorkDir(), ns_id)). |
| 22 | Append("app-scope-global"). |
| 23 | Append("app-scope-local"). |
| 24 | Append("use-mq-eventfd") |
Filip Tehlar | 5ebdd51 | 2023-12-14 13:06:54 +0100 | [diff] [blame] | 25 | if len(ns_id_optional) > 0 { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 26 | s.Append(fmt.Sprintf("namespace-id %[1]s", ns_id)). |
| 27 | Append(fmt.Sprintf("namespace-secret %[1]s", ns_id)) |
Filip Tehlar | 5ebdd51 | 2023-12-14 13:06:54 +0100 | [diff] [blame] | 28 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 29 | return s.Close().ToString() |
Filip Tehlar | 4b3598e | 2023-09-02 08:54:21 +0200 | [diff] [blame] | 30 | } |
Filip Tehlar | 4b3598e | 2023-09-02 08:54:21 +0200 | [diff] [blame] | 31 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 32 | func XEchoVclClientUdpTest(s *VethsSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 33 | testXEchoVclClient(s, "udp") |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 34 | } |
| 35 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 36 | func XEchoVclClientTcpTest(s *VethsSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 37 | testXEchoVclClient(s, "tcp") |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 38 | } |
| 39 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 40 | func testXEchoVclClient(s *VethsSuite, proto string) { |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 41 | port := "12345" |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 42 | serverVpp := s.GetContainerByName("server-vpp").VppInstance |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 43 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 44 | serverVeth := s.GetInterfaceByName(ServerInterfaceName) |
| 45 | serverVpp.Vppctl("test echo server uri %s://%s/%s fifo-size 64k", proto, serverVeth.Ip4AddressString(), port) |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 46 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 47 | echoClnContainer := s.GetTransientContainerByName("client-app") |
| 48 | echoClnContainer.CreateFile("/vcl.conf", getVclConfig(echoClnContainer)) |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 49 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 50 | testClientCommand := "vcl_test_client -N 100 -p " + proto + " " + serverVeth.Ip4AddressString() + " " + port |
| 51 | s.Log(testClientCommand) |
| 52 | echoClnContainer.AddEnvVar("VCL_CONFIG", "/vcl.conf") |
| 53 | o := echoClnContainer.Exec(testClientCommand) |
| 54 | s.Log(o) |
| 55 | s.AssertContains(o, "CLIENT RESULTS") |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 56 | } |
| 57 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 58 | func XEchoVclServerUdpTest(s *VethsSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 59 | testXEchoVclServer(s, "udp") |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 60 | } |
| 61 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 62 | func XEchoVclServerTcpTest(s *VethsSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 63 | testXEchoVclServer(s, "tcp") |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 64 | } |
| 65 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 66 | func testXEchoVclServer(s *VethsSuite, proto string) { |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 67 | port := "12345" |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 68 | srvVppCont := s.GetContainerByName("server-vpp") |
| 69 | srvAppCont := s.GetContainerByName("server-app") |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 70 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 71 | srvAppCont.CreateFile("/vcl.conf", getVclConfig(srvVppCont)) |
| 72 | srvAppCont.AddEnvVar("VCL_CONFIG", "/vcl.conf") |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 73 | vclSrvCmd := fmt.Sprintf("vcl_test_server -p %s %s", proto, port) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 74 | srvAppCont.ExecServer(vclSrvCmd) |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 75 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 76 | serverVeth := s.GetInterfaceByName(ServerInterfaceName) |
| 77 | serverVethAddress := serverVeth.Ip4AddressString() |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 78 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 79 | clientVpp := s.GetContainerByName("client-vpp").VppInstance |
| 80 | o := clientVpp.Vppctl("test echo client uri %s://%s/%s fifo-size 64k verbose mbytes 2", proto, serverVethAddress, port) |
| 81 | s.Log(o) |
| 82 | s.AssertContains(o, "Test finished at") |
Filip Tehlar | efe875e | 2023-09-04 14:17:52 +0200 | [diff] [blame] | 83 | } |
| 84 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 85 | func testVclEcho(s *VethsSuite, proto string) { |
Filip Tehlar | 71fc194 | 2023-05-22 15:48:51 +0200 | [diff] [blame] | 86 | port := "12345" |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 87 | srvVppCont := s.GetContainerByName("server-vpp") |
| 88 | srvAppCont := s.GetContainerByName("server-app") |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 89 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 90 | srvAppCont.CreateFile("/vcl.conf", getVclConfig(srvVppCont)) |
| 91 | srvAppCont.AddEnvVar("VCL_CONFIG", "/vcl.conf") |
| 92 | srvAppCont.ExecServer("vcl_test_server " + port) |
Filip Tehlar | 71fc194 | 2023-05-22 15:48:51 +0200 | [diff] [blame] | 93 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 94 | serverVeth := s.GetInterfaceByName(ServerInterfaceName) |
| 95 | serverVethAddress := serverVeth.Ip4AddressString() |
Filip Tehlar | 71fc194 | 2023-05-22 15:48:51 +0200 | [diff] [blame] | 96 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 97 | echoClnContainer := s.GetTransientContainerByName("client-app") |
| 98 | echoClnContainer.CreateFile("/vcl.conf", getVclConfig(echoClnContainer)) |
Filip Tehlar | 71fc194 | 2023-05-22 15:48:51 +0200 | [diff] [blame] | 99 | |
Filip Tehlar | d3b47c6 | 2023-05-31 12:26:59 +0200 | [diff] [blame] | 100 | testClientCommand := "vcl_test_client -p " + proto + " " + serverVethAddress + " " + port |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 101 | echoClnContainer.AddEnvVar("VCL_CONFIG", "/vcl.conf") |
| 102 | o := echoClnContainer.Exec(testClientCommand) |
| 103 | s.Log(o) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 106 | func VclEchoTcpTest(s *VethsSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 107 | testVclEcho(s, "tcp") |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 108 | } |
| 109 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 110 | func VclEchoUdpTest(s *VethsSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 111 | testVclEcho(s, "udp") |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 112 | } |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 113 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 114 | func VclRetryAttachTest(s *VethsSuite) { |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 115 | testRetryAttach(s, "tcp") |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 116 | } |
| 117 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 118 | func testRetryAttach(s *VethsSuite, proto string) { |
| 119 | srvVppContainer := s.GetTransientContainerByName("server-vpp") |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 120 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 121 | echoSrvContainer := s.GetContainerByName("server-app") |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 122 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 123 | echoSrvContainer.CreateFile("/vcl.conf", getVclConfig(echoSrvContainer)) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 124 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 125 | echoSrvContainer.AddEnvVar("VCL_CONFIG", "/vcl.conf") |
| 126 | echoSrvContainer.ExecServer("vcl_test_server -p " + proto + " 12346") |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 127 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 128 | s.Log("This whole test case can take around 3 minutes to run. Please be patient.") |
| 129 | s.Log("... Running first echo client test, before disconnect.") |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 130 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 131 | serverVeth := s.GetInterfaceByName(ServerInterfaceName) |
| 132 | serverVethAddress := serverVeth.Ip4AddressString() |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 133 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 134 | echoClnContainer := s.GetTransientContainerByName("client-app") |
| 135 | echoClnContainer.CreateFile("/vcl.conf", getVclConfig(echoClnContainer)) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 136 | |
| 137 | testClientCommand := "vcl_test_client -U -p " + proto + " " + serverVethAddress + " 12346" |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 138 | echoClnContainer.AddEnvVar("VCL_CONFIG", "/vcl.conf") |
| 139 | o := echoClnContainer.Exec(testClientCommand) |
| 140 | s.Log(o) |
| 141 | s.Log("... First test ended. Stopping VPP server now.") |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 142 | |
| 143 | // Stop server-vpp-instance, start it again and then run vcl-test-client once more |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 144 | srvVppContainer.VppInstance.Disconnect() |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 145 | stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'" |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 146 | srvVppContainer.Exec(stopVppCommand) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 147 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 148 | s.SetupServerVpp() |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 149 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 150 | s.Log("... VPP server is starting again, so waiting for a bit.") |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 151 | time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen |
| 152 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 153 | s.Log("... Running second echo client test, after disconnect and re-attachment.") |
| 154 | o = echoClnContainer.Exec(testClientCommand) |
| 155 | s.Log(o) |
| 156 | s.Log("Done.") |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 157 | } |