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