blob: 88acefd144ffa47159e79e829ad6eec5c0e9548e [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 Tehlar71fc1942023-05-22 15:48:51 +02008func (s *VethsSuite) testVclEcho(proto string) {
9 port := "12345"
10 srvVppCont := s.getContainerByName("server-vpp")
11 srvAppCont := s.getContainerByName("server-app")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000012
Filip Tehlar71fc1942023-05-22 15:48:51 +020013 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
25 testClientCommand := "vcl_test_client -E -p " + proto + " " + serverVethAddress + " " + port
26 echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
27 o := echoClnContainer.exec(testClientCommand)
28 s.log(o)
Filip Tehlar229f5fc2022-08-09 14:44:47 +000029}
30
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010031func (s *VethsSuite) TestVclEchoTcp() {
Filip Tehlar229f5fc2022-08-09 14:44:47 +000032 s.testVclEcho("tcp")
33}
34
Filip Tehlar71fc1942023-05-22 15:48:51 +020035func (s *VethsSuite) TestVclEchoUdp() {
36 s.testVclEcho("udp")
Filip Tehlar229f5fc2022-08-09 14:44:47 +000037}
Maros Ondrejicka0db15752022-10-12 22:58:01 +020038
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010039func (s *VethsSuite) TestVclRetryAttach() {
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010040 s.skip("this test takes too long, for now it's being skipped")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020041 s.testRetryAttach("tcp")
42}
43
Maros Ondrejicka11a03e92022-12-01 09:56:37 +010044func (s *VethsSuite) testRetryAttach(proto string) {
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010045 srvVppContainer := s.getTransientContainerByName("server-vpp")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020046
Filip Tehlar71fc1942023-05-22 15:48:51 +020047 echoSrvContainer := s.getContainerByName("server-app")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010048
Maros Ondrejickae7625d02023-02-28 16:55:01 +010049 serverVclConfContent := fmt.Sprintf(vclTemplate, echoSrvContainer.getContainerWorkDir(), "1")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010050 echoSrvContainer.createFile("/vcl.conf", serverVclConfContent)
51
52 echoSrvContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010053 echoSrvContainer.execServer("vcl_test_server -p " + proto + " 12346")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020054
Maros Ondrejicka87531802022-12-19 20:35:27 +010055 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 Ondrejickaffa3f602023-01-26 10:07:29 +010057
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010058 serverVeth := s.netInterfaces[serverInterfaceName]
Maros Ondrejickae7625d02023-02-28 16:55:01 +010059 serverVethAddress := serverVeth.ip4AddressString()
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010060
Filip Tehlar71fc1942023-05-22 15:48:51 +020061 echoClnContainer := s.getTransientContainerByName("client-app")
Maros Ondrejickae7625d02023-02-28 16:55:01 +010062 clientVclConfContent := fmt.Sprintf(vclTemplate, echoClnContainer.getContainerWorkDir(), "2")
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010063 echoClnContainer.createFile("/vcl.conf", clientVclConfContent)
64
65 testClientCommand := "vcl_test_client -U -p " + proto + " " + serverVethAddress + " 12346"
66 echoClnContainer.addEnvVar("VCL_CONFIG", "/vcl.conf")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010067 o := echoClnContainer.exec(testClientCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010068 s.log(o)
Maros Ondrejicka87531802022-12-19 20:35:27 +010069 s.log("... First test ended. Stopping VPP server now.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020070
71 // Stop server-vpp-instance, start it again and then run vcl-test-client once more
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010072 srvVppContainer.vppInstance.disconnect()
Maros Ondrejicka0db15752022-10-12 22:58:01 +020073 stopVppCommand := "/bin/bash -c 'ps -C vpp_main -o pid= | xargs kill -9'"
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010074 srvVppContainer.exec(stopVppCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010075
76 s.setupServerVpp()
Maros Ondrejicka0db15752022-10-12 22:58:01 +020077
Maros Ondrejicka87531802022-12-19 20:35:27 +010078 s.log("... VPP server is starting again, so waiting for a bit.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020079 time.Sleep(30 * time.Second) // Wait a moment for the re-attachment to happen
80
Maros Ondrejicka87531802022-12-19 20:35:27 +010081 s.log("... Running second echo client test, after disconnect and re-attachment.")
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010082 o = echoClnContainer.exec(testClientCommand)
Maros Ondrejickaffa3f602023-01-26 10:07:29 +010083 s.log(o)
Maros Ondrejicka87531802022-12-19 20:35:27 +010084 s.log("Done.")
Maros Ondrejicka0db15752022-10-12 22:58:01 +020085}
Maros Ondrejicka5b746312022-11-16 12:51:11 +010086
87func (s *VethsSuite) TestTcpWithLoss() {
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010088 serverVpp := s.getContainerByName("server-vpp").vppInstance
Maros Ondrejicka5b746312022-11-16 12:51:11 +010089
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010090 serverVeth := s.netInterfaces[serverInterfaceName]
91 serverVpp.vppctl("test echo server uri tcp://%s/20022",
Maros Ondrejickae7625d02023-02-28 16:55:01 +010092 serverVeth.ip4AddressString())
Maros Ondrejicka5b746312022-11-16 12:51:11 +010093
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +010094 clientVpp := s.getContainerByName("client-vpp").vppInstance
Maros Ondrejicka5b746312022-11-16 12:51:11 +010095
96 // Ensure that VPP doesn't abort itself with NSIM enabled
97 // Warning: Removing this ping will make the test fail!
Maros Ondrejickae7625d02023-02-28 16:55:01 +010098 clientVpp.vppctl("ping %s", serverVeth.ip4AddressString())
Maros Ondrejicka5b746312022-11-16 12:51:11 +010099
100 // Add loss of packets with Network Delay Simulator
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100101 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 Ondrejicka5b746312022-11-16 12:51:11 +0100105
106 // Do echo test from client-vpp container
Maros Ondrejicka2908f8c2023-02-02 08:58:04 +0100107 output := clientVpp.vppctl("test echo client uri tcp://%s/20022 mbytes 50",
Maros Ondrejickae7625d02023-02-28 16:55:01 +0100108 serverVeth.ip4AddressString())
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100109 s.assertEqual(true, len(output) != 0)
110 s.assertNotContains(output, "failed: timeout")
Maros Ondrejicka87531802022-12-19 20:35:27 +0100111 s.log(output)
Maros Ondrejicka5b746312022-11-16 12:51:11 +0100112}