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