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