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 | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame^] | 23 | serverVethAddress := s.veths["vppsrv"].Address() |
| 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" + |
| 28 | " socket-name " + echoSrvContainer.GetContainerWorkDir() + "/var/run/app_ns_sockets/1" + |
| 29 | " use-app-socket-api" + |
| 30 | " uri " + uri |
| 31 | s.log(serverCommand) |
| 32 | err := echoSrvContainer.execServer(serverCommand) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 33 | s.assertNil(err) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 34 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 35 | echoClnContainer := s.getContainerByName("client-application") |
| 36 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame^] | 37 | clientCommand := "vpp_echo client" + |
| 38 | " socket-name " + echoClnContainer.GetContainerWorkDir() + "/var/run/app_ns_sockets/2" + |
| 39 | " use-app-socket-api uri " + uri |
| 40 | s.log(clientCommand) |
| 41 | o, err := echoClnContainer.exec(clientCommand) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 42 | s.assertNil(err) |
Maros Ondrejicka | 98a91e8 | 2022-12-06 15:38:05 +0100 | [diff] [blame] | 43 | |
Maros Ondrejicka | 8753180 | 2022-12-19 20:35:27 +0100 | [diff] [blame] | 44 | s.log(o) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 45 | } |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 46 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 47 | func (s *VethsSuite) TestVclRetryAttach() { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame^] | 48 | 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] | 49 | s.testRetryAttach("tcp") |
| 50 | } |
| 51 | |
Maros Ondrejicka | 11a03e9 | 2022-12-01 09:56:37 +0100 | [diff] [blame] | 52 | func (s *VethsSuite) testRetryAttach(proto string) { |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame^] | 53 | srvVppContainer := s.getContainerCopyByName("server-vpp") |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 54 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 55 | echoSrvContainer := s.getContainerByName("server-application") |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame^] | 56 | |
| 57 | serverVclConfContent := fmt.Sprintf(vclTemplate, echoSrvContainer.GetContainerWorkDir(), "1") |
| 58 | echoSrvContainer.createFile("/vcl.conf", serverVclConfContent) |
| 59 | |
| 60 | echoSrvContainer.addEnvVar("VCL_CONFIG", "/vcl.conf") |
| 61 | err := echoSrvContainer.execServer("vcl_test_server -p " + proto + " 12346") |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 62 | s.assertNil(err) |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 63 | |
Maros Ondrejicka | 8753180 | 2022-12-19 20:35:27 +0100 | [diff] [blame] | 64 | s.log("This whole test case can take around 3 minutes to run. Please be patient.") |
| 65 | s.log("... Running first echo client test, before disconnect.") |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame^] | 66 | |
| 67 | serverVeth := s.veths[serverInterfaceName] |
| 68 | serverVethAddress := serverVeth.Address() |
| 69 | |
| 70 | echoClnContainer := s.getContainerCopyByName("client-application") |
| 71 | clientVclConfContent := fmt.Sprintf(vclTemplate, echoClnContainer.GetContainerWorkDir(), "2") |
| 72 | echoClnContainer.createFile("/vcl.conf", clientVclConfContent) |
| 73 | |
| 74 | testClientCommand := "vcl_test_client -U -p " + proto + " " + serverVethAddress + " 12346" |
| 75 | echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf") |
| 76 | o, err := echoClnContainer.exec(testClientCommand) |
| 77 | s.log(o) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 78 | s.assertNil(err) |
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 | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 84 | _, err = srvVppContainer.exec(stopVppCommand) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 85 | s.assertNil(err) |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame^] | 86 | |
| 87 | s.setupServerVpp() |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 88 | |
Maros Ondrejicka | 8753180 | 2022-12-19 20:35:27 +0100 | [diff] [blame] | 89 | s.log("... VPP server is starting again, so waiting for a bit.") |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 90 | time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen |
| 91 | |
Maros Ondrejicka | 8753180 | 2022-12-19 20:35:27 +0100 | [diff] [blame] | 92 | s.log("... Running second echo client test, after disconnect and re-attachment.") |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame^] | 93 | o, err = echoClnContainer.exec(testClientCommand) |
| 94 | s.log(o) |
Maros Ondrejicka | 0e79abb | 2022-12-06 19:46:24 +0100 | [diff] [blame] | 95 | s.assertNil(err) |
Maros Ondrejicka | 8753180 | 2022-12-19 20:35:27 +0100 | [diff] [blame] | 96 | s.log("Done.") |
Maros Ondrejicka | 0db1575 | 2022-10-12 22:58:01 +0200 | [diff] [blame] | 97 | } |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 98 | |
| 99 | func (s *VethsSuite) TestTcpWithLoss() { |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 100 | serverContainer := s.getContainerByName("server-vpp") |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 101 | |
| 102 | serverVpp := NewVppInstance(serverContainer) |
| 103 | s.assertNotNil(serverVpp) |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 104 | serverVpp.set2VethsServer() |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 105 | err := serverVpp.start() |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 106 | s.assertNil(err, "starting VPP failed") |
| 107 | |
Maros Ondrejicka | ffa3f60 | 2023-01-26 10:07:29 +0100 | [diff] [blame^] | 108 | serverVeth := s.veths[serverInterfaceName] |
| 109 | _, err = serverVpp.vppctl("test echo server uri tcp://%s/20022", serverVeth.Address()) |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 110 | s.assertNil(err, "starting echo server failed") |
| 111 | |
Maros Ondrejicka | db823ed | 2022-12-14 16:30:04 +0100 | [diff] [blame] | 112 | clientContainer := s.getContainerByName("client-vpp") |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 113 | |
| 114 | clientVpp := NewVppInstance(clientContainer) |
| 115 | s.assertNotNil(clientVpp) |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 116 | clientVpp.set2VethsClient() |
| 117 | err = clientVpp.start() |
| 118 | s.assertNil(err, "starting VPP failed") |
| 119 | |
| 120 | // Ensure that VPP doesn't abort itself with NSIM enabled |
| 121 | // Warning: Removing this ping will make the test fail! |
| 122 | _, err = serverVpp.vppctl("ping 10.10.10.2") |
| 123 | s.assertNil(err, "ping failed") |
| 124 | |
| 125 | // Add loss of packets with Network Delay Simulator |
| 126 | _, err = clientVpp.vppctl("set nsim poll-main-thread delay 0.01 ms bandwidth 40 gbit packet-size 1400 packets-per-drop 1000") |
| 127 | s.assertNil(err, "configuring NSIM failed") |
| 128 | _, err = clientVpp.vppctl("nsim output-feature enable-disable host-vppcln") |
| 129 | s.assertNil(err, "enabling NSIM failed") |
| 130 | |
| 131 | // Do echo test from client-vpp container |
| 132 | output, err := clientVpp.vppctl("test echo client uri tcp://10.10.10.1/20022 mbytes 50") |
| 133 | s.assertNil(err) |
| 134 | s.assertEqual(true, len(output) != 0) |
| 135 | s.assertNotContains(output, "failed: timeout") |
Maros Ondrejicka | 8753180 | 2022-12-19 20:35:27 +0100 | [diff] [blame] | 136 | s.log(output) |
Maros Ondrejicka | 5b74631 | 2022-11-16 12:51:11 +0100 | [diff] [blame] | 137 | } |