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