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 | 71fc194 | 2023-05-22 15:48:51 +0200 | [diff] [blame] | 18 | func (s *VethsSuite) testVclEcho(proto string) { |
| 19 | port := "12345" |
| 20 | srvVppCont := s.getContainerByName("server-vpp") |
| 21 | srvAppCont := s.getContainerByName("server-app") |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 22 | |
Filip Tehlar | 71fc194 | 2023-05-22 15:48:51 +0200 | [diff] [blame] | 23 | serverVclConfContent := fmt.Sprintf(vclTemplate, srvVppCont.getContainerWorkDir(), "1") |
| 24 | srvAppCont.createFile("/vcl.conf", serverVclConfContent) |
| 25 | srvAppCont.addEnvVar("VCL_CONFIG", "/vcl.conf") |
| 26 | srvAppCont.execServer("vcl_test_server " + port) |
| 27 | |
| 28 | serverVeth := s.netInterfaces[serverInterfaceName] |
| 29 | serverVethAddress := serverVeth.ip4AddressString() |
| 30 | |
| 31 | echoClnContainer := s.getTransientContainerByName("client-app") |
| 32 | clientVclConfContent := fmt.Sprintf(vclTemplate, echoClnContainer.getContainerWorkDir(), "2") |
| 33 | echoClnContainer.createFile("/vcl.conf", clientVclConfContent) |
| 34 | |
Filip Tehlar | d3b47c6 | 2023-05-31 12:26:59 +0200 | [diff] [blame] | 35 | testClientCommand := "vcl_test_client -p " + proto + " " + serverVethAddress + " " + port |
Filip Tehlar | 71fc194 | 2023-05-22 15:48:51 +0200 | [diff] [blame] | 36 | echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf") |
| 37 | o := echoClnContainer.exec(testClientCommand) |
| 38 | s.log(o) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 41 | func (s *VethsSuite) TestVclEchoTcp() { |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 42 | s.testVclEcho("tcp") |
| 43 | } |
| 44 | |
Filip Tehlar | 71fc194 | 2023-05-22 15:48:51 +0200 | [diff] [blame] | 45 | func (s *VethsSuite) TestVclEchoUdp() { |
| 46 | s.testVclEcho("udp") |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 47 | } |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 48 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 49 | func (s *VethsSuite) TestVclRetryAttach() { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 50 | 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] | 51 | s.testRetryAttach("tcp") |
| 52 | } |
| 53 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 54 | func (s *VethsSuite) testRetryAttach(proto string) { |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 55 | srvVppContainer := s.getTransientContainerByName("server-vpp") |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 56 | |
Filip Tehlar | 71fc194 | 2023-05-22 15:48:51 +0200 | [diff] [blame] | 57 | echoSrvContainer := s.getContainerByName("server-app") |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 58 | |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 59 | serverVclConfContent := fmt.Sprintf(vclTemplate, echoSrvContainer.getContainerWorkDir(), "1") |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 60 | echoSrvContainer.createFile("/vcl.conf", serverVclConfContent) |
| 61 | |
| 62 | echoSrvContainer.addEnvVar("VCL_CONFIG", "/vcl.conf") |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 63 | echoSrvContainer.execServer("vcl_test_server -p " + proto + " 12346") |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 64 | |
Maros Ondrejicka | 8753180 | 2022-12-19 20:35:27 +0100 | [diff] [blame] | 65 | s.log("This whole test case can take around 3 minutes to run. Please be patient.") |
| 66 | s.log("... Running first echo client test, before disconnect.") |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 67 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 68 | serverVeth := s.netInterfaces[serverInterfaceName] |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 69 | serverVethAddress := serverVeth.ip4AddressString() |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 70 | |
Filip Tehlar | 71fc194 | 2023-05-22 15:48:51 +0200 | [diff] [blame] | 71 | echoClnContainer := s.getTransientContainerByName("client-app") |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 72 | clientVclConfContent := fmt.Sprintf(vclTemplate, echoClnContainer.getContainerWorkDir(), "2") |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 73 | echoClnContainer.createFile("/vcl.conf", clientVclConfContent) |
| 74 | |
| 75 | testClientCommand := "vcl_test_client -U -p " + proto + " " + serverVethAddress + " 12346" |
| 76 | echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf") |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 77 | o := echoClnContainer.exec(testClientCommand) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 78 | s.log(o) |
Maros Ondrejicka | 8753180 | 2022-12-19 20:35:27 +0100 | [diff] [blame] | 79 | s.log("... First test ended. Stopping VPP server now.") |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 80 | |
| 81 | // 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] | 82 | srvVppContainer.vppInstance.disconnect() |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 83 | 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] | 84 | srvVppContainer.exec(stopVppCommand) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 85 | |
| 86 | s.setupServerVpp() |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 87 | |
Maros Ondrejicka | 8753180 | 2022-12-19 20:35:27 +0100 | [diff] [blame] | 88 | s.log("... VPP server is starting again, so waiting for a bit.") |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 89 | time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen |
| 90 | |
Maros Ondrejicka | 8753180 | 2022-12-19 20:35:27 +0100 | [diff] [blame] | 91 | s.log("... Running second echo client test, after disconnect and re-attachment.") |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 92 | o = echoClnContainer.exec(testClientCommand) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame] | 93 | s.log(o) |
Maros Ondrejicka | 8753180 | 2022-12-19 20:35:27 +0100 | [diff] [blame] | 94 | s.log("Done.") |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 95 | } |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 96 | |
| 97 | func (s *VethsSuite) TestTcpWithLoss() { |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 98 | serverVpp := s.getContainerByName("server-vpp").vppInstance |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 99 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 100 | serverVeth := s.netInterfaces[serverInterfaceName] |
| 101 | serverVpp.vppctl("test echo server uri tcp://%s/20022", |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 102 | serverVeth.ip4AddressString()) |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 103 | |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 104 | clientVpp := s.getContainerByName("client-vpp").vppInstance |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 105 | |
| 106 | // Ensure that VPP doesn't abort itself with NSIM enabled |
| 107 | // Warning: Removing this ping will make the test fail! |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 108 | clientVpp.vppctl("ping %s", serverVeth.ip4AddressString()) |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 109 | |
| 110 | // Add loss of packets with Network Delay Simulator |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 111 | clientVpp.vppctl("set nsim poll-main-thread delay 0.01 ms bandwidth 40 gbit" + |
| 112 | " packet-size 1400 packets-per-drop 1000") |
| 113 | |
| 114 | clientVpp.vppctl("nsim output-feature enable-disable host-vppcln") |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 115 | |
| 116 | // Do echo test from client-vpp container |
Maros Ondrejicka | 2908f8c | 2023-02-02 08:58:04 +0100 | [diff] [blame] | 117 | output := clientVpp.vppctl("test echo client uri tcp://%s/20022 mbytes 50", |
Maros Ondrejicka | e7625d0 | 2023-02-28 16:55:01 +0100 | [diff] [blame] | 118 | serverVeth.ip4AddressString()) |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 119 | s.assertEqual(true, len(output) != 0) |
| 120 | s.assertNotContains(output, "failed: timeout") |
Maros Ondrejicka | 8753180 | 2022-12-19 20:35:27 +0100 | [diff] [blame] | 121 | s.log(output) |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 122 | } |