blob: 7cf4ab75dfd682d2769a7ab0dc372578f643f581 [file] [log] [blame]
Filip Tehlar229f5fc2022-08-09 14:44:47 +00001package main
2
3import (
Maros Ondrejickaffa3f602023-01-26 10:07:29 +01004 "fmt"
Maros Ondrejicka0db15752022-10-12 22:58:01 +02005 "time"
Filip Tehlar229f5fc2022-08-09 14:44:47 +00006)
7
Maros Ondrejicka11a03e92022-12-01 09:56:37 +01008func (s *VethsSuite) TestVclEchoQuic() {
Maros Ondrejicka87531802022-12-19 20:35:27 +01009 s.skip("quic test skipping..")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000010 s.testVclEcho("quic")
11}
12
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010013func (s *VethsSuite) TestVclEchoUdp() {
Maros Ondrejicka87531802022-12-19 20:35:27 +010014 s.skip("udp echo currently broken in vpp, skipping..")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000015 s.testVclEcho("udp")
16}
17
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010018func (s *VethsSuite) TestVclEchoTcp() {
Filip Tehlar229f5fc2022-08-09 14:44:47 +000019 s.testVclEcho("tcp")
20}
21
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010022func (s *VethsSuite) testVclEcho(proto string) {
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010023 serverVethAddress := s.netInterfaces["vppsrv"].IP4AddressString()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010024 uri := proto + "://" + serverVethAddress + "/12344"
Filip Tehlar229f5fc2022-08-09 14:44:47 +000025
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010026 echoSrvContainer := s.getContainerByName("server-application")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010027 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)
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010032 echoSrvContainer.execServer(serverCommand)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000033
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010034 echoClnContainer := s.getContainerByName("client-application")
35
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010036 clientCommand := "vpp_echo client" +
37 " socket-name " + echoClnContainer.GetContainerWorkDir() + "/var/run/app_ns_sockets/2" +
38 " use-app-socket-api uri " + uri
39 s.log(clientCommand)
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010040 o := echoClnContainer.exec(clientCommand)
Maros Ondrejicka98a91e82022-12-06 15:38:05 +010041
Maros Ondrejicka87531802022-12-19 20:35:27 +010042 s.log(o)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000043}
Maros Ondrejicka0db15752022-10-12 22:58:01 +020044
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010045func (s *VethsSuite) TestVclRetryAttach() {
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010046 s.skip("this test takes too long, for now it's being skipped")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020047 s.testRetryAttach("tcp")
48}
49
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010050func (s *VethsSuite) testRetryAttach(proto string) {
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010051 srvVppContainer := s.getTransientContainerByName("server-vpp")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020052
Maros Ondrejickadb823ed2022-12-14 16:30:04 +010053 echoSrvContainer := s.getContainerByName("server-application")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010054
55 serverVclConfContent := fmt.Sprintf(vclTemplate, echoSrvContainer.GetContainerWorkDir(), "1")
56 echoSrvContainer.createFile("/vcl.conf", serverVclConfContent)
57
58 echoSrvContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010059 echoSrvContainer.execServer("vcl_test_server -p " + proto + " 12346")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020060
Maros Ondrejicka87531802022-12-19 20:35:27 +010061 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 Ondrejickaffa3f602023-01-26 10:07:29 +010063
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010064 serverVeth := s.netInterfaces[serverInterfaceName]
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010065 serverVethAddress := serverVeth.IP4AddressString()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010066
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010067 echoClnContainer := s.getTransientContainerByName("client-application")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010068 clientVclConfContent := fmt.Sprintf(vclTemplate, echoClnContainer.GetContainerWorkDir(), "2")
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 Ondrejicka2908f8c2023-02-02 08:58:04 +010073 o := echoClnContainer.exec(testClientCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010074 s.log(o)
Maros Ondrejicka87531802022-12-19 20:35:27 +010075 s.log("... First test ended. Stopping VPP server now.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020076
77 // Stop server-vpp-instance, start it again and then run vcl-test-client once more
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010078 srvVppContainer.vppInstance.disconnect()
Maros Ondrejicka0db15752022-10-12 22:58:01 +020079 stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010080 srvVppContainer.exec(stopVppCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010081
82 s.setupServerVpp()
Maros Ondrejicka0db15752022-10-12 22:58:01 +020083
Maros Ondrejicka87531802022-12-19 20:35:27 +010084 s.log("... VPP server is starting again, so waiting for a bit.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020085 time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
86
Maros Ondrejicka87531802022-12-19 20:35:27 +010087 s.log("... Running second echo client test, after disconnect and re-attachment.")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010088 o = echoClnContainer.exec(testClientCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010089 s.log(o)
Maros Ondrejicka87531802022-12-19 20:35:27 +010090 s.log("Done.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020091}
Maros Ondrejicka5b746312022-11-16 12:51:11 +010092
93func (s *VethsSuite) TestTcpWithLoss() {
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010094 serverVpp := s.getContainerByName("server-vpp").vppInstance
Maros Ondrejicka5b746312022-11-16 12:51:11 +010095
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010096 serverVeth := s.netInterfaces[serverInterfaceName]
97 serverVpp.vppctl("test echo server uri tcp://%s/20022",
Maros Ondrejicka7550dd22023-02-07 20:40:27 +010098 serverVeth.IP4AddressString())
Maros Ondrejicka5b746312022-11-16 12:51:11 +010099
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100100 clientVpp := s.getContainerByName("client-vpp").vppInstance
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100101
102 // Ensure that VPP doesn't abort itself with NSIM enabled
103 // Warning: Removing this ping will make the test fail!
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100104 clientVpp.vppctl("ping %s", serverVeth.IP4AddressString())
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100105
106 // Add loss of packets with Network Delay Simulator
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100107 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 Ondrejicka5b746312022-11-16 12:51:11 +0100111
112 // Do echo test from client-vpp container
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100113 output := clientVpp.vppctl("test echo client uri tcp://%s/20022 mbytes 50",
Maros Ondrejicka7550dd22023-02-07 20:40:27 +0100114 serverVeth.IP4AddressString())
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100115 s.assertEqual(true, len(output) != 0)
116 s.assertNotContains(output, "failed: timeout")
Maros Ondrejicka87531802022-12-19 20:35:27 +0100117 s.log(output)
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100118}