blob: cf4c32ed020efbbebed31654cc5e6f3dee6c3ff7 [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
Filip Tehlar4b3598e2023-09-02 08:54:21 +02008const 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 Tehlar71fc1942023-05-22 15:48:51 +020018func (s *VethsSuite) testVclEcho(proto string) {
19 port := "12345"
20 srvVppCont := s.getContainerByName("server-vpp")
21 srvAppCont := s.getContainerByName("server-app")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000022
Filip Tehlar71fc1942023-05-22 15:48:51 +020023 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 Tehlard3b47c62023-05-31 12:26:59 +020035 testClientCommand := "vcl_test_client -p " + proto + " " + serverVethAddress + " " + port
Filip Tehlar71fc1942023-05-22 15:48:51 +020036 echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
37 o := echoClnContainer.exec(testClientCommand)
38 s.log(o)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000039}
40
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010041func (s *VethsSuite) TestVclEchoTcp() {
Filip Tehlar229f5fc2022-08-09 14:44:47 +000042 s.testVclEcho("tcp")
43}
44
Filip Tehlar71fc1942023-05-22 15:48:51 +020045func (s *VethsSuite) TestVclEchoUdp() {
46 s.testVclEcho("udp")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000047}
Maros Ondrejicka0db15752022-10-12 22:58:01 +020048
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010049func (s *VethsSuite) TestVclRetryAttach() {
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010050 s.skip("this test takes too long, for now it's being skipped")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020051 s.testRetryAttach("tcp")
52}
53
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010054func (s *VethsSuite) testRetryAttach(proto string) {
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010055 srvVppContainer := s.getTransientContainerByName("server-vpp")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020056
Filip Tehlar71fc1942023-05-22 15:48:51 +020057 echoSrvContainer := s.getContainerByName("server-app")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010058
Maros Ondrejickae7625d02023-02-28 16:55:01 +010059 serverVclConfContent := fmt.Sprintf(vclTemplate, echoSrvContainer.getContainerWorkDir(), "1")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010060 echoSrvContainer.createFile("/vcl.conf", serverVclConfContent)
61
62 echoSrvContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010063 echoSrvContainer.execServer("vcl_test_server -p " + proto + " 12346")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020064
Maros Ondrejicka87531802022-12-19 20:35:27 +010065 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 Ondrejickaffa3f602023-01-26 10:07:29 +010067
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010068 serverVeth := s.netInterfaces[serverInterfaceName]
Maros Ondrejickae7625d02023-02-28 16:55:01 +010069 serverVethAddress := serverVeth.ip4AddressString()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010070
Filip Tehlar71fc1942023-05-22 15:48:51 +020071 echoClnContainer := s.getTransientContainerByName("client-app")
Maros Ondrejickae7625d02023-02-28 16:55:01 +010072 clientVclConfContent := fmt.Sprintf(vclTemplate, echoClnContainer.getContainerWorkDir(), "2")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010073 echoClnContainer.createFile("/vcl.conf", clientVclConfContent)
74
75 testClientCommand := "vcl_test_client -U -p " + proto + " " + serverVethAddress + " 12346"
76 echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010077 o := echoClnContainer.exec(testClientCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010078 s.log(o)
Maros Ondrejicka87531802022-12-19 20:35:27 +010079 s.log("... First test ended. Stopping VPP server now.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020080
81 // Stop server-vpp-instance, start it again and then run vcl-test-client once more
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010082 srvVppContainer.vppInstance.disconnect()
Maros Ondrejicka0db15752022-10-12 22:58:01 +020083 stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010084 srvVppContainer.exec(stopVppCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010085
86 s.setupServerVpp()
Maros Ondrejicka0db15752022-10-12 22:58:01 +020087
Maros Ondrejicka87531802022-12-19 20:35:27 +010088 s.log("... VPP server is starting again, so waiting for a bit.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020089 time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
90
Maros Ondrejicka87531802022-12-19 20:35:27 +010091 s.log("... Running second echo client test, after disconnect and re-attachment.")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010092 o = echoClnContainer.exec(testClientCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010093 s.log(o)
Maros Ondrejicka87531802022-12-19 20:35:27 +010094 s.log("Done.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020095}
Maros Ondrejicka5b746312022-11-16 12:51:11 +010096
97func (s *VethsSuite) TestTcpWithLoss() {
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010098 serverVpp := s.getContainerByName("server-vpp").vppInstance
Maros Ondrejicka5b746312022-11-16 12:51:11 +010099
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100100 serverVeth := s.netInterfaces[serverInterfaceName]
101 serverVpp.vppctl("test echo server uri tcp://%s/20022",
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100102 serverVeth.ip4AddressString())
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100103
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100104 clientVpp := s.getContainerByName("client-vpp").vppInstance
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100105
106 // Ensure that VPP doesn't abort itself with NSIM enabled
107 // Warning: Removing this ping will make the test fail!
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100108 clientVpp.vppctl("ping %s", serverVeth.ip4AddressString())
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100109
110 // Add loss of packets with Network Delay Simulator
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100111 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 Ondrejicka5b746312022-11-16 12:51:11 +0100115
116 // Do echo test from client-vpp container
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100117 output := clientVpp.vppctl("test echo client uri tcp://%s/20022 mbytes 50",
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100118 serverVeth.ip4AddressString())
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100119 s.assertEqual(true, len(output) != 0)
120 s.assertNotContains(output, "failed: timeout")
Maros Ondrejicka87531802022-12-19 20:35:27 +0100121 s.log(output)
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100122}