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