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